Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent deletion of database or shared preference on clear app

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?

Image

like image 364
Rohit Avatar asked Dec 19 '13 05:12

Rohit


1 Answers

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

like image 57
TheIT Avatar answered Sep 23 '22 02:09

TheIT