0
0
Android Kotlinmobile~5 mins

Room database setup in Android Kotlin - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
A@Database
B@Dao
C@Table
D@Entity
What does @Dao stand for in Room?
AData Access Object
BDatabase Access Operation
CData Annotation Object
DDirect Access Operation
How do you create a Room database instance?
Anew RoomDatabase()
BRoom.databaseBuilder(context, DbClass::class.java, "name").build()
CRoom.createDatabase()
DDatabaseBuilder.create()
Which of these is NOT a recommended practice with Room?
ARunning queries on the main thread
BUsing @Entity for tables
CDefining DAO interfaces
DUsing LiveData with queries
What is the purpose of the @Database annotation?
ATo create tables automatically
BTo mark a class as a DAO
CTo define the database holder and list entities
DTo run queries
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.