Prevent deletion of database or shared preference on clear app

流过昼夜 提交于 2019-12-22 09:37:50

问题


I want to prevent the deletion of shared preferences or database on clear such that it will clear only when the app is uninstalled. How can I keep shared preference safe on app. clear?


回答1:


It is worth noting that there are three types of data clearing in Android, of which your application has no control over:

  • Clear Data
  • Clear Cache
  • Clear Defaults

Clear Data Clear data will clear everything under the application's working directory. This includes any shared preferences, databases and files saved by the application which reside in the application directory. This will also clear the application's cache, as it is also part of the application's working directory.

Clear Cache The application has access to a cache directory to save files to, mainly for the purpose of caching such as generated images or temporary files.

Clear Defaults This options will clear any intents registered to this application.

Uninstalling an application will clear all three sets of data. Therefore the only way to maintain data between installs is to save it to external storage, but note that both the user and every application has access to the external storage and therefore may be modified or deleted at any point.

Links worth reading:

http://developer.android.com/guide/topics/data/data-storage.html#

Android: Save file permanently (even after clear data / uninstall)

What's the difference between clear cache & clear data in Android settings



来源:https://stackoverflow.com/questions/20673862/prevent-deletion-of-database-or-shared-preference-on-clear-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!