Recall & Review
beginner
What is Room in Android development?
Room is a library that provides an easy way to work with SQLite databases by using simple annotations and abstracting boilerplate code.
Click to reveal answer
beginner
Which annotation is used to define an entity (table) in Room?
The @Entity annotation is used to mark a Kotlin data class as a table in the Room database.Click to reveal answer
beginner
What is the role of the @Dao interface in Room?
The @Dao interface defines methods to access the database, such as queries, inserts, updates, and deletes.
Click to reveal answer
intermediate
How do you create the Room database instance in your app?
You create the database instance using Room.databaseBuilder(context, YourDatabase::class.java, "database_name").build() inside a singleton or application class.
Click to reveal answer
intermediate
Why should Room database operations be done off the main thread?
Because database operations can be slow, doing them on the main thread can freeze the UI. Room enforces this by throwing an error if you try to do heavy operations on the main thread.
Click to reveal answer
Which annotation marks a data class as a table in Room?
✗ Incorrect
The @Entity annotation is used to define a table in Room.
What does @Dao stand for in Room?
✗ Incorrect
@Dao stands for Data Access Object, which defines database interaction methods.
How do you create a Room database instance?
✗ Incorrect
Room.databaseBuilder() is the correct way to create a database instance.
Which of these is NOT a recommended practice with Room?
✗ Incorrect
Running queries on the main thread can freeze the UI and is not recommended.
What is the purpose of the @Database annotation?
✗ Incorrect
@Database annotation defines the database class and its entities.
Explain the main components needed to set up a Room database in an Android app.
Think about the classes and annotations you need to define tables, access data, and create the database.
You got /4 concepts.
Why is it important to avoid running Room database operations on the main thread? How can you handle this?
Consider what happens if the app waits too long for data and how Kotlin helps with background work.
You got /4 concepts.