Android Programming

Tutorial No 6 : Storage Options for Android Apps

Storage Options for Android Apps

Android provides various options for you to save valuable application data. The option you choose depends on your specific needs, such as whether the data should be private for your application or accessible to other installed applications (and the user) and how much space your data requires.

App-specific storage: This storage allows to store files that are intended for your app's use only, either in dedicated directories within an internal storage volume or different dedicated directories within external storage. This is the private storage area of apps and hence the developer use the directories within internal storage to save sensitive information that other apps can't access.
From external storage, getExternalFilesDir() or getExternalCacheDir()
For this type of access,No permission is required to access for internal storage and no permission is required for external storage when your app is used on devices that run Android 4.4 (API level 19) or higher.
If you delete the apps, all the app specific data will be deleted.

Shared storage: This storage allows to store files that your app intends to share with other apps, including media, documents, and other files.
For accessing such data MediaStore API is used
For this type of access,READ_EXTERNAL_STORAGE permission is required when accessing other apps' files on Android 11 (API level 30) or higher and READ_EXTERNAL_STORAGE or WRITE_EXTERNAL_STORAGE permissions are required when accessing other apps' files on Android 10 (API level 29) and Permissions are required for all files on Android 9 (API level 28) or lower
The data created by one app can be accessed by other apps also who has the READ_EXTERNAL_STORAGE permission If you delete the app, all the app specific data will remain as it is.

Preferences:This storage allows to store private, primitive data in key-value pairs.
Jetpack Preferences library is required to access such data.
No permission is required to access the data and these data can be accessed by the same app only.In case if you delete app then data will also be deleted.

Databases: This storage allows to Store structured data in a private database using the Room persistence library.
For accessing such data Room persistence library is used
For this type of No permission is required.Even only the app who has created the data can access it
If you delete the app, all the app specific data will be deleted.