How to keep shared preference data after clearing the cache of application from settings

6.9k views Asked by At

I have observed that when i click on clear cache in settings>apps>particular app, Shared preference data get deleted.

how to keep shared preference data even if i clear the clear the cache? is it possible? if possible means give idea about that

2

There are 2 answers

0
Kartheek On BEST ANSWER

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

The only way to have persistent data is to use the SD card, but again, users won't like to have the data on their card after the app is uninstalled or users can un-mount the SD card.

Or you can consider:

  1. Storing the data on a remote server with some kind of authentication to retrieve it
  2. Using Data Backup service
0
Oladipo Olasemo On

Shared preferences is generally used to store temporary information on a user's device. So generally it holds temporary information/data.

To store data that will survive the 'Clear Cache' action, you can store information in an sqllite database.

To do this, you need to implement a content provider that will encapsulate access to the sqllite database, it will help you store and retrieve data that will not be deleted when the cache is cleared. find more information on how to create a content provider here : http://developer.android.com/training/basics/data-storage/databases.html