Storage in Android

Android uses a file system that is like a disk-based file system of other platforms. The Android system provides different options to save application data:

  • Application-specific storage in Android
  • Shared storage in Android
  • Preferences in Android
  • Databases in Android

Let us go through these all one by one.

1. Android Application-specific storage

In this, the stored data is meant only for a specific application’s use. It is stored either in a dedicated directory inside the internal storage or in external storage. The sensitive data, that is specific to the app and shall not be accessible to other apps is generally stored in Internal Storage. There are certain things about it that are:

a. To access it, we have two ways:

  • Internal Storage
  • getFilesDir() or getCacheDir()
  • External Storage
  • getExternalFilesDir() or getExternalCacherDir()

b. Permission is not required for Internal Storage as well as for External Storage. When considering external storage, we do not need permission for Android version 4.4(API level 19) or higher.

c. If the app data is in internal storage, other apps cannot access it. If the data is in external storage, files can be accessed by other apps.

d. If the application is uninstalled by any means, the data files also get deleted.

2. Shared Storage in Android

In this, the stored data is meant to be shared among other apps as well. It includes data such as multimedia, documents, etc. There are certain things about it that are:

a. Access the data with MediaStore API and Storage Access Framework.

b. To read the media file use these permissions: READ_EXTERNAL_STORAGE or WRITE_EXTERNAL_STORAGE for Android 10 or higher.

c. You can access the media files by other files through READ_EXTERNAL_STORAGE and the document files, through system file picker.

d. If you uninstall the app, the data would not be deleted from the External Storage.

3. Android Preferences

They store the data in a private database. It stores the data in the form of a key-value pair. There are certain things about it that are:

a. Data is stored in a key-value pair.

b. It can be accessed through the Jetpack preference library.

c. Data from this cannot be accessed through other applications.

d. When you uninstall the app, the data gets deleted.

4. Android Databases

In this, the data is stored as structured data in a private database. For that, it uses the Room persistence library. There are certain things about it that are:

a. It has structured data

b. To access the data use Room persistence library

c. No other application can access the data

d. On the uninstallation of the application, the data gets deleted too.

#android tutorials #android storage #external storage in android #internal storage in android #storage in android

Storage in Android - How to save data and files in Android? - DataFlair
2.45 GEEK