Android Databases

With data and data storage a common requirement in most mobile applications, the question of which is the best database to use often comes up. In this article, we are going to cover what to consider when choosing a database for your Android app, and what the available options are. This will allow you to make an informed choice the next time you require a database for your mobile app.

What is a database for Android?

A database for Android is a form of persistent data storage intended for use in apps for Android devices. It often consists of on-device, local storage so the app continues to be available even if the device loses connectivity. Due to its inclusion in the Android Software Development Kit (SDK), SQLite, an open-source relational database, is the most common database technology associated with Android applications. For Android apps, SQLite is most often paired with Room, a framework for managing the lifecycle of objects. However, as this article will go on to discuss, there are other simpler options for modern mobile applications.

What to look for in a mobile database

Although databases all provide the ability to store, query, and manipulate data, not all databases are created equal.

Before choosing, you need to understand your application requirements. Here are a couple of questions that can help you:

Database Type

What sort of data will you be storing?

Are you going to store structured/unstructured data or large files? Should the data be shared among users or can it be stored only on the device?

How will you access your data?

Do you need to perform complicated queries to join data from multiple data sources?

Hosting Method

How will users be interacting with your application’s data?

Do users expect to be able to collaborate in real-time without any noticeable delays? Does data need to be shared between users and devices?

Different types of Android databases

Now you know what things to consider in an Android database, let’s look at some of the types of Android databases available. They mainly fall into three categories: relational, key-value, and object-oriented .

Relational database - Uses tables and shared columns, aka keys, to form relationships between tables. Most common example is SQLite, available inside the Android SDK. Great if relationships between entities are important.

Key-Value database - Uses a key to single value mapping to store information. Often used in Android databases for saving things such as user settings. Example would be Shared Preferences for Android.

Object-oriented database - Can work with complex data objects as seen in object-oriented programming languages. Able to do fast queries with complex data. Code is often simpler as well due to closeness in structure between the database and objects in code. Atlas Device SDKs provide an object-oriented database.

Different ways to host your database

There are some factors in how a database can be hosted and how it works that are worth considering:

Local storage - Having the data stored locally and available offline is an important feature in mobile applications. With their portability, connections to the network can be inconsistent on mobile devices. With data stored locally on a mobile device, apps continue to be usable, even when offline, leading to a much better user experience.

Cloud - Many mobile applications require data sharing across users, devices, and a centralized back end — a capability not supported by local-only storage solutions. This means that mobile developers need to save their app data to the cloud or a self-hosted server.

A cloud database has several advantages. For example, MongoDB Atlas , MongoDB’s multi-cloud application data platform, combines a flexible document data model and unified query interface, to provide a first-class developer experience that can power almost any class of application while meeting the most demanding requirements for resilience, scale, and data privacy. However, the driver used to communicate with Atlas requires network access at all times, making the experience less than optimal for mobile use cases where devices are constantly disconnecting and reconnecting.

Server - You may prefer to self-host your data, using your own servers and data center. A database that can be self-hosted and work with mobile is therefore a consideration. However, this again would require internet access to reach so faces the same limitations around connectivity.

Locally and in the cloud - One option that addresses connectivity issues and ensures real-time data sharing capabilities is to use a cloud database and a local database. Then, connect the two with a synchronization mechanism. This is the most common architecture for building real-time, reactive mobile apps that appear “always on” for users. However, developing and maintaining an effective synchronization mechanism requires writing lots of networking code, error handling, and conflict resolution logic that is often complex and time-consuming for mobile development teams to devote resources to. Taking time to build custom data syncing mechanisms also means less time can be spent on building differentiating features within the application.