Android Development & Storage

Android uses a file system that's similar to disk-based file systems on other platforms.

Author: COPS SDG Published on: June 15, 2021

Native Android & Storage

Introduction

Android uses a file system that's similar to disk-based file systems on other platforms. The system provides several options for you to save your app data:

  • App-specific storage: Store files that are meant for your app's use only, either in dedicated directories within an internal storage volume or different dedicated directories within external storage. Use the directories within internal storage to save sensitive information that other apps shouldn't access.
  • Shared storage: Store files that your app intends to share with other apps, including media, documents, and other files.
  • Preferences: Store private, primitive data in key-value pairs.
  • Databases: Store structured data in a private database using the Room persistence library.

Storing data locally

Using Shared Preferences

Shared Preferences is the way to go if you’re saving primitive data as key-value pairs. It requires a key, which is a String, and the corresponding value for the said key. The value can be any of the following: a boolean, float, int, long, or another string.

Shared Preferences in Android with Example - GeeksforGeeks

https://www.youtube.com/watch?v=fJEFZ6EOM9o

Using internal storage

It is specifically for when you need to store data on the file system, but you don’t want other apps or users to have access. This data storage is so private, in fact, that it’s deleted from the device as soon as you uninstall your app.

Internal Storage in Android with Example - GeeksforGeeks

External Storage

To give users better control over their files and cut down on clutter, apps now have scoped access to external storage by default. This means that they can tap into the specific directory on external storage and the media that the app creates.

Android External Storage with Examples - Tutlane

SQLite database

Android provides support for apps to use SQLite databases for data storage. The databases you create remain specific to your app and can only be accessed inside your app. Of course, you should have at least some knowledge of SQL before you attempt to store data with an SQLite database.

We recommend using android library "Room" to make task easier.

Room database Library

The Room persistence library provides an abstraction layer over SQLite to allow fluent database access while harnessing the full power of SQLite. In particular, Room provides the following benefits:

  • Compile-time verification of SQL queries.
  • Convenience annotations that minimize repetitive and error-prone boilerplate code.
  • Streamlined database migration paths.

Because of these considerations, we highly recommend that you use Room instead of using the SQLite APIs directly.

https://www.youtube.com/watch?v=ONb_MuPBBlg

NOTE:

Don't forget to give permissions to your app for accessing your device local storage .

Challenge and submission

This Blog is a part of CSoC'21 Dev Frontend.

Remember, deadline for this task is June 21st, 2021 23:59.

Let's dig in to the challenges of this week .

COPS-IITBHU/csoc-2021-task-2

All details have been provided in the README.md file.

For submission create your own repo and make a PR in above repo and add your entry into Android.md with apk link and repo link only .