caching - How do I take advantage of Android's "Clear Cache" button -


In Android settings when clicking on an app, in the "Manage apps" activity, the data is divided into applications, data Is done, and there is also a button to clear the cash cache. My app caches audio files and I would like the user to be able to clean the cache using this button. How do I store them so that they will get along with the cache and the user can clear them? I have tried to store files using 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 no data and no cache.

I can not reproduce your problem, maybe something else is wrong.

By using the following application, I was able to create a file in the cache directory and then clear the application by using the Manage applications under Settings in the Manifest and what I said There is no need to change anything in order to go.

  the public class enhances the CreateCacheFile activity {@ Override Creates the Bundle (Saved InstanceState) on Public Zero {super.onCreate (SavedInstanceState); SetContentView (R.layout.main); Button Button = (Button) Find VibiBiID (RID Craftfile Button); Button.setOnClickListener (New View.OnClickListener) Click on {@Override Public Zero (see V) {file file = new file (CreateCacheFile.this.getCacheDir (), "temp.txt"); {file.createNewFile () Try: fwitter ef = new flamer (file); buffed witter bw = new buffed water (FW); bw written ("hello world"); bw.Newline (); bw.close ();} cache (IOE expansion E) {Toast. Make Text (CreateCacheFile.this, "Error!", Toast .LENGTH_SHORT) Show ();}}}); }}  

After running the application (and clicking the button to create the file):

  $ adb -d shell # ls / data / Data / com.example.CreateCacheFile / cache temp.txt # cat /data/data/com.example.CreateCacheFile/cache/temp.txt Hello World #  

Manage applications that 4KB The location of the cache is to use it after clicking on the button:

  # ls /data/data/com.example.CreateCacheFile/cache # cat / data / data /com.example.CreateCacheFile/cache/temp.txt Temp.txt: A file or directory such as #  

At this point the application is running Location of the 0 KB manage port access to cash.


Comments