Skip to content
AndroidTesters
Building Android apps

When should an Android app use a database instead of preferences?

Use key-value storage for a few independent settings, and a database when your app manages records people need to find, sort, relate, or update together. This guide shows how to choose and what to consider before changing storage.

Written byAndroidTesters Editorial

6 min read

A person uses a smartphone while reviewing an app.
Photo by Michael Burrows on Pexels
In this article
  1. Start with the shape of the data
  2. Use key-value storage for focused settings
  3. Use a database for records and queries
  4. Compare the options, then make the call
  5. Frequently asked questions
  6. Key takeaways
At a glance
  • Choose key-value storage for a small set of independent settings, such as theme or notification preferences.
  • Choose a database when you need records, queries, sorting, relationships, or reliable multi-record updates.
  • For most new Android apps, consider DataStore for settings and Room for structured local data.
  • Keep large files, such as images, in file or cloud storage; save their references in your database when useful.

Use the simplest storage that matches how the data is shaped and how the app needs to access it. A theme choice and a searchable list of saved recipes may both be stored on the device, but they have different needs.

The key question is not how many bytes you have today. Ask what the app must do with the data as it grows, changes, and is used across screens.

Start with the shape of the data

Preferences represent individual choices or values, usually identified by a key. Database data is organized as records with fields, and can be queried or related to other records.

  • Think about the unit. Is this one value such as a selected language, or a collection of entities such as saved articles?
  • List the ways the app reads it. Will it fetch one setting, or filter records by status, sort them by date, and search their contents?
  • Consider how updates relate. Does changing one value stand alone, or must several records change together to preserve a consistent result?
  • Look ahead, without guessing. Choose for requirements you can explain, not for a hypothetical future that may never arrive.

For example, a reading app might store its preferred text size as a setting, while storing each bookmark as a record with a page, title, and timestamp. The fact that both are small does not make them the same kind of data.

Use key-value storage for focused settings

Settings are a good fit for key-value storage when each value can be read or updated independently and the app does not need database-style queries. For new Android development, DataStore is generally the recommended option for small settings; Preferences DataStore offers key-value pairs, while Proto DataStore stores typed data defined by a schema.

Hands hold a smartphone while a person checks an app setting.
Photo by Liliana Drew on Pexels
  • Good candidates: a theme mode, a chosen sort order, a dismissed onboarding flag, or a small set of account-level display options.
  • Read the values as state. DataStore exposes data as a Flow, which works well when the interface should react to settings changes.
  • Update through its API. Use DataStore's update operations rather than maintaining a separate in-memory value that can drift from persisted state.
  • Plan for change. If using Proto DataStore, evolve its schema carefully; for either type, define sensible defaults and handle errors.
Tip

Keep preference keys and defaults in one well-defined part of the app. This makes it easier to see which settings exist and to avoid screens inventing conflicting values.

SharedPreferences may already be present in an older app and can be adequate for simple legacy settings. For a new feature, compare its needs with DataStore rather than automatically copying the old pattern. Neither preferences API is a good place for a growing collection that users need to search, sort, or edit item by item.

Use a database for records and queries

Choose a local database when the app works with structured data that needs to be retrieved in different ways. Room provides an Android persistence layer over SQLite, with entities, data access objects, and query support; it is a practical default for many app-owned relational datasets.

  • Records need filtering or sorting. Examples include tasks by due date, downloaded items by status, or messages in a conversation.
  • Entities have relationships. A project may have many tasks, or a user may save many products; representing these as related records is clearer than encoding them in a single preference value.
  • Several changes must stay consistent. Transactions can group related database operations so the app does not leave partially updated data after an interruption.
  • The dataset is expected to grow. Queries let the app retrieve what a screen needs instead of loading and rewriting one large serialized collection.
Watch out

A database adds schema design, query maintenance, and migration work. Do not introduce Room just because a value is important; use it when the data model or access pattern justifies those costs.

Room is not a home for every kind of local data. Store large media files in the filesystem or an appropriate remote store, then keep a path, URI, or other reference in the database if the app needs to associate that file with a record.

Compare the options, then make the call

Use this comparison to narrow the choice. The distinction is about the work the app needs to perform, not a universal size limit: there is no single number of keys or bytes that makes preferences become a database.

Two developers discuss an app project together at a desk.
Photo by Thirdman on Pexels
NeedKey-value storageRoom database
Typical dataIndependent settingsStructured records
Read patternGet a value by keyFilter, sort, or join records
RelationshipsNot its main purposeModel related entities
UpdatesChange a settingCoordinate record changes
Typical Android choiceDataStoreRoom over SQLite
Choose storage by the questions your app must answer about its data.
  1. Write down the data model. List the fields, how many kinds of entities exist, and whether one item refers to another.
  2. Write down real screen queries. Include the reads needed now, such as finding unfinished tasks or showing recent downloads.
  3. Check update boundaries. If multiple records must change together, account for transactions and consistency.
  4. Pick the smallest suitable tool. Use DataStore for focused settings and Room when records or queries call for a database.
  5. Review the decision as requirements change. If a setting evolves into a searchable collection, plan a deliberate migration instead of forcing it into a preference.

For a feature that genuinely mixes both patterns, use both. A music app could keep its playback preference in DataStore and its downloaded-track catalogue in Room; avoid duplicating the same source of truth in both.

Frequently asked questions

Is DataStore a database?

DataStore persists data, but it is designed for small settings or typed objects rather than relational queries. Use Room when you need records, filtering, relationships, or database transactions.

Can I store a list in preferences?

Some key-value APIs can hold simple collections, but that does not make them suitable for a growing, independently editable list. If users need to search, sort, or update individual items, model those items in a database.

Should I replace SharedPreferences in an existing app?

Not automatically. Assess the feature, migration effort, and risk; simple existing settings may not justify a change. For new settings or a planned refactor, review current Android documentation for the appropriate DataStore approach.

Do I need Room for data that must survive app restarts?

No. Persistence alone does not require a database. A few durable settings can use DataStore, while structured records and queryable local data are stronger Room use cases.

Key takeaways

  • Use key-value storage for a small number of independent settings, not as a substitute for a searchable collection.
  • Use Room when data has record structure, relationships, meaningful queries, or coordinated updates.
  • Data size alone is not the deciding factor; access patterns and consistency needs matter more.
  • Keep large files outside the database and store references when records need to point to them.
  • Revisit the choice when the feature changes, and check current Android documentation for implementation and migration details.

Shipping a build? Have it tested on real Android devices with AndroidTesters. Learn more

Prepared with AI assistance and checked against AndroidTesters' editorial guidelines. AndroidTesters is not affiliated with Google. Rules and numbers change: confirm important details in the official documentation before you act.