Question

Android provides following options for data storage:

Shared Preferences - Store private primitive data in key-value pairs.

Internal Storage - Store private data on the device memory.

External Storage - Store public data on the shared external storage.

SQLite Databases - Store structured data in a private database.

Cache - Cache data during application is running.(May be clear on shortage of space)

What I was wondering is the life time of these storage.

  1. Which storage(s) clears on application close (Obviously cache)
  2. Which storage(s) clears on application re-install
  3. Which storage(s) clears on application update
  4. Which storage(s) clears on application un-install
  5. Which storage(s) clears on application clear data
  6. Which storage(s) clears on mobile factory reset
  7. Which storage(s) clears on Rom upgrade/change

An extension to this question is, using which storage my data is more secure in terms of loss and in terms of access by unauthorized resources (users, applications in case of root).

Was it helpful?

Solution

Which storage(s) clears on application close (Obviously cache)

Cache

Which storage(s) clears on application re-install

Cache

Which storage(s) clears on application update

Cache

Which storage(s) clears on application un-install

Cache, SQLite, Shared Preferences

Which storage(s) clears on application clear data

Cache, SQLite, Shared Preferences

Which storage(s) clears on mobile factory reset

It clears all, but not External Storage data

An extension to this question is, using which storage my data is more secure in terms of loss and in terms of access by unauthorized resources (users, applications in case of root).

It is best to store the data in the SQLite in the encrypted form. If your device is rooted then it means you can access even the SQLite.

OTHER TIPS

Application Close : Cache files wont be deleted after application close.

As per android docs,

When the device is low on internal storage space, Android may delete these cache files to recover space. However, you should not rely on the system to clean up these files for you. You should always maintain the cache files yourself and stay within a reasonable limit of space consumed, such as 1MB. When the user uninstalls your application, these files are removed.

Application re-install and un-install : Cache, Shared Preferences, Internal Storage and Databases will be removed when un-installing the app.

Application Update: Usually everything you had on previous version will be restored. Docs are also not clear about this.

Application Clear data : Everything except External Storage will be deleted permanently.

Factory Reset: Doing a Factory Reset will erase all the apps and its data except preinstalled ones. You can restore your apps with google account but not data (If data not backed up with BackUp Api.

And for your final question, There is NO Secure data storage if you store data in device. Even External data storage can be removed with USB file options. For secure data, you should maintain user data on your server and get it on demand.

Hope I was clear.

In answer to your question, persistent storage (SQL, Internal\External storage, SharedPreferences) acts mostly the same by default, and Cache acts different.

Persistent storage - will be NOT be cleared in following scenarios: 1, 2, 3 - will be cleared in other scenarios.

Internal\External storage - can survive application removal (if configured appropriately), so, has possibility to NOT be deleted on 4 & 5, if you specifically handle this.

Cache - will be cleared in all scenarios (you may be able to access cache after application close in certain instances, but not reliably).

7* (ROM updates can retain application data using a backup solution, otherwise, would act same as 6)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top