Login to manage your account

Please enter a valid email address.
Forgot Password?
Please enter a valid password.
OR

Don't have an account yet? Sign up

How do you store data in an Android app, and what is Room?

The options, matched to the use case:

  • DataStore — key-value or typed proto storage for small data such as user preferences and flags. It replaces SharedPreferences, which had a synchronous API that could block the main thread and no error signalling. DataStore is asynchronous, coroutine and Flow based, and transactional.
  • Room — an abstraction over SQLite for structured relational data. It is the standard answer for anything queryable.
  • Internal storage — files private to the app, deleted on uninstall.
  • MediaStore and the Storage Access Framework — for shared media and user-selected documents, since scoped storage restricted direct filesystem access from Android 10.
  • EncryptedSharedPreferences or the Keystore — for tokens and sensitive values. Credentials should never sit in plain preferences.

Room specifically has three parts: Entity classes annotated to define tables, a DAO interface declaring queries, and a Database class tying them together. Its main advantage is that SQL is verified at compile time — a typo in a query is a build error rather than a runtime crash, which raw SQLite could not offer. It also returns Flow, so the UI updates automatically when the underlying data changes, and integrates with coroutines so queries run off the main thread.

Note: Migrations are the practical difficulty. Changing a schema requires a Migration, and falling back to destructive migration wipes user data — acceptable in development, never in production.

All Android interview questions

Login to manage your account

Please enter a valid email address.
Forgot Password?
Please enter a valid password.
OR

Don't have an account yet? Sign up as