The Getcachedir () method is used to get the/data/data/<application Package>/cache directory
The Getfilesdir () method is used to get the/data/data/<application package>/files directory
--------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------
In the process of running the application, if you need to save data to the phone, the data is usually saved in SDcard.
Most applications create a folder directly under the root of the sdcard, and then save the data in that folder.
That way, when the app is uninstalled, the data remains in the SDcard, leaving the junk data.
What if you want your app to be uninstalled, and the data associated with that app is erased?
The Context.getexternalfilesdir () method allows you to get to sdcard/android/data/your app's package name/files/directory, usually put some long-time saved data
The Context.getexternalcachedir () method allows you to get to sdcard/android/data/your app package name/cache/directory, typically storing temporary cache data
If you use the above method, when your app is uninstalled by the user, sdcard/android/data/your app's package name/All files in this directory will be deleted, leaving no spam messages.
And the "Clear data" and "clear cache" options in the above two directories corresponding to the application details of settings--
If you want to save the downloaded content, do not put it in the above directory
--------------------------------------------------------------------------------------------------------------- --------------------------------------
The better program will write a method to get the cache address, as follows:
[Java] view plain copy
- Public String Getdiskcachedir (context context) {
- String CachePath = null;
- if (Environment.MEDIA_MOUNTED.equals (Environment.getexternalstoragestate ())
- || ! Environment.isexternalstorageremovable ()) {
- CachePath = Context.getexternalcachedir (). GetPath ();
- } else {
- CachePath = Context.getcachedir (). GetPath ();
- }
- return CachePath;
- }
As you can see, when the SD card is present or the SD card is not removable, call the Getexternalcachedir () method to get the cache path, otherwise call the Getcachedir () method to get the cache path. The former obtains the/sdcard/android/data/<application Package>/cache this path, the latter obtains is the/data/data/<application package >/cache this path.
The role of Getcachedir (), Getfilesdir (), Getexternalfilesdir (), Getexternalcachedir ()