Android - Storage Options

Android provides many ways for developers to store their application data. Developers should understand their application requirements before selecting the method to store their data.

This post is to provide a high level view on how to select the application storage options

Shared Preference

Shared Preference allow you to store primitive data type as key-value pair. The data is persistent across user session even if your application is killed. Shared Preference data can only be access within the same application. Also, Shared Preference stored the data into memory after first access from the application. So, it is not recommendable for large dataset.

Shared Preference is suitable for


  • Small and simple storage. Just a key and a small dataset with simple data structure
  • Data that requires frequent access
  • Passing data between Activities

Internal Storage

Internal Storage save your data into application private folder. These saved data cannot be access by other application. When you uninstall your application, your application data in internal storage will be deleted.

Internal Storage is suitable for


  • Large dataset with complex data structure and does not require to shared with other application
  • Data that are not frequently used but require permanent storage

Internal Storage with Cache Directory

Internal Storage allow you to cache your file with the use of getCacheDir(). Android may delete these cache files if the system is low in Internal Storage.


Internal Storage with Cache Directory is suitable for


  • Large dataset that is only required temporarily and the lost of the data will not impact the application

External Storage

External Storage allow you stored large dataset and shared between different applications. The external storage can be SDCard or Internal Storage.

External Storage is suitable for

  • Large dataset that you wish to shared between different application

External Storage with Cache Directory

External Storage allow you to cache your file with the use of getExternalCacheDir(). Android may delete these cache files if the system is low in External Storage


External Storage with Cache Directory is suitable for


  • Large dataset that is only required temporarily shared between application and the lost of the data will not impact the application


Database

Android support SQLites database. Developers can create complex database schema for their application to store their data. Database can only be access by name with any class in the application

Database is suitable for


  • Large complex and logical dataset that require database schema to ensure efficient data access


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

Comments

Popular Posts