Challenge - 5 Problems
Room Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate1:00remaining
What is the role of an Entity class in Android Room?
In Android Room, what does an Entity class represent?
Attempts:
2 left
💡 Hint
Think about how data is stored in a database.
✗ Incorrect
An Entity class defines a table in the database. Each field in the class corresponds to a column in that table.
❓ ui_behavior
intermediate1:30remaining
What happens when you call a DAO query method on the main thread?
Consider a DAO method annotated with @Query that fetches data. What happens if you call this method directly on the main thread?
Attempts:
2 left
💡 Hint
Think about Android's rule for long operations on the main thread.
✗ Incorrect
Room does not allow database queries on the main thread to avoid freezing the UI. It throws a runtime exception if you try.
❓ lifecycle
advanced1:30remaining
When is the Room database instance created in a typical Android app?
In an Android app using Room, when is the database instance usually created?
Attempts:
2 left
💡 Hint
Think about how to avoid creating multiple database instances.
✗ Incorrect
Creating the database once at app start and reusing it avoids overhead and ensures data consistency.
📝 Syntax
advanced2:00remaining
What is the correct syntax to define a DAO method that inserts a User entity?
Choose the correct Kotlin DAO method syntax to insert a User entity into the database.
Android Kotlin
interface UserDao {
// Insert method here
}Attempts:
2 left
💡 Hint
The @Insert annotation goes before the function, and suspend is used for coroutines.
✗ Incorrect
The correct syntax uses @Insert annotation before a suspend function that takes the entity as a parameter.
🔧 Debug
expert2:30remaining
Why does this Room database build fail with "Cannot find symbol" error?
Given this code snippet, why does the build fail with a "Cannot find symbol" error for the DAO interface?
@Entity
data class Product(val id: Int, val name: String)
@Database(entities = [Product::class], version = 1)
abstract class AppDatabase : RoomDatabase() {
abstract fun productDao(): ProductDao
}
// ProductDao interface is missing in the project.
Attempts:
2 left
💡 Hint
Check if all referenced classes exist in the project.
✗ Incorrect
The build fails because the AppDatabase references ProductDao, but ProductDao interface is not defined anywhere.