Android app file cache Getcachedir () and Getexternalcachedir ()

Source: Internet
Author: User

If the Android reference program needs to cache temporary files, the system provides a manageable "internal cache" and an "external cache" that is not manageable, calling the Getcachedir () and Getexternalcachedir () methods, respectively, to access them from the current context. Files stored in the "internal cache" will be deleted when a program is unloaded, and may be deleted when the system is running in low-run space, but files stored in the "external cache" will not be deleted because the Android system does not allow the tracking of empty controls in the external media.

When the application is running, if it needs to save data to the phone, it usually saves the data 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--

Android app file cache Getcachedir () and Getexternalcachedir ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.