Android Room Interview Questions
SQLite persistence, entities, DAOs, and migrations.
50 questions in this topic · 8 sample questions below
Practice Room in the quiz engine
Sample questions
A DAO returns Flow<List<User>> from a query on the users table. You update an unrelated row in the same table. What does Room's observer emit?
Why: Room's InvalidationTracker works at the table level, so any write to an observed table re-runs the query and re-emits the whole result. The idea that Room emits only changed rows is a common misconception; add distinctUntilChanged to suppress identical re-emissions.
You call fallbackToDestructiveMigration() and ship a schema-version bump without a Migration object. On update, what happens to existing user data?
Why: fallbackToDestructiveMigration tells Room to drop and recreate the database when no migration path exists, so all local data is lost. Believing it preserves data is the classic trap; use a Migration object to keep data.
Why does Room require @Transaction on a DAO method that returns an @Relation-based POJO?
Why: Room resolves an @Relation by issuing a separate query for the child data, so without @Transaction the parent and child reads could observe different states after a concurrent write. It is about read consistency, not that @Relation mechanically requires a transaction.
On which thread does a suspend DAO function annotated with a @Query execute its actual database I/O?
Why: Room's generated code for suspend DAO functions dispatches the blocking I/O onto its own query executor, so you can safely call them from Main without manual withContext. The belief that they run on the caller's thread or need Dispatchers.IO is a widespread misconception.
You model a many-to-many relationship between Student and Course. What is the idiomatic Room approach?
Why: Room has no notion of a persistable collection field, so many-to-many needs an explicit cross-reference table wired with associateBy = Junction. Room cannot persist a raw List<Course>, so that option would fail to compile.
A query loads 500 authors, each with an @Relation list of books, producing one child query per author. What is this pattern called and Room's mitigation?
Why: Loading a parent list plus per-parent relation queries is the N+1 problem, and Room's generated relation code batches child ids into IN (...) queries rather than firing one round trip per parent. WAL mode and SELECT DISTINCT do not address the fan-out of relation queries.
What does @Upsert do that @Insert(onConflict = REPLACE) does not?
Why: @Upsert attempts an insert and falls back to an UPDATE on conflict, so it does not delete the row, unlike REPLACE which does a DELETE + INSERT that can cascade to child rows and reassign auto ids. Treating them as identical is the trap.
With a foreign key declared onDelete = CASCADE from Book to Author, when do the child Book rows actually get deleted?
Why: Room turns on SQLite foreign-key enforcement, so a CASCADE deletes dependent child rows automatically when the parent is removed. You do not need to run PRAGMA foreign_keys yourself; Room does it for every connection.
Practice all 50 Room questions
These 8 are a sample. The full Room bank is scored, tracks your progress, and explains every answer.
More Android interview topics
- Android Hilt interview questions
- Android Coroutines & Flow interview questions
- Android Design Patterns interview questions
- Android Mobile System Design interview questions
- Android Coding Interview Patterns interview questions
- Android NDK interview questions
- Android Sensors interview questions
- Android Security interview questions
- Android Jetpack Compose interview questions
- Android Canvas & Animation interview questions
- Android CI/CD interview questions
- Android Git interview questions
- Android Unit Testing interview questions
- Android Kotlin interview questions
- Android Retrofit interview questions
- Android Architecture interview questions
- Android Android Framework interview questions
- Android Kotlin Multiplatform interview questions
- Android WorkManager & Background interview questions
- Android Performance & Memory interview questions