In Android's settings, in the "Manage Applications" activity when clicking on an app, the data is broken down into Application, Data, and cache. There is also a button to clear the cache. My app caches audio files and I would like the user to be able to clear the cache using this button. How do I store them so they get lumped in with the cache and the user can clear them? I've tried storing files using both of the following techniques:
newFile = File.createTempFile("mcb", ".mp3", context.getCacheDir());
newFile = new File(context.getCacheDir(), "mcb.mp3");
newFile.createNewFile();
In both cases, these files are listed as Data and not Cache.
I can't reproduce your problem, perhaps something else is wrong.
Using the following application, I was able to create a file in the cache directory and then clear it using the Manage Applications function under Settings. I didn't have to change anything in the manifest and from what I can tell, you really shouldn't mess with the
android:allowClearUserData
option.After running the application (and clicking the button to create the file):
Manage Applications reports that 4KB of space is in use for Cache. After clicking the button to clear it:
At this point Manage Applications reports that 0KB of space is in use for Cache.
I think you have to make use of
android:allowClearUserData
andandroid:manageSpaceActivity
under your<application>
tag to see that option in 'Manage Applications'. See http://developer.android.com/guide/topics/manifest/application-element.html for more information.Alternatively, have an option for clearing cache in your activity.