Let's think about it this way for a second
Room is a library that wraps Android's built-in SQLite database in a type-safe, Kotlin-friendly way — there are three core concepts: Entity (`@Entity`, defines the table structure as a data class), DAO (`@Dao`, defines database operations - insert/query/delete - as an interface), and Database (`@Database`, the class that combines your Entities/DAOs). Pair Room with a ViewModel (Advanced lesson 1), and your data survives even an app restart — unlike RAM-only ViewModel state.
Let's connect this to a real scenario
Define `@Entity data class TodoEntity(@PrimaryKey val id: String, val title: String, val isDone: Boolean)`, then write `@Dao interface TodoDao { @Query("SELECT * FROM TodoEntity") suspend fun getAll(): List<TodoEntity>; @Insert suspend fun insert(todo: TodoEntity) }` — calling `todoDao.insert(newTodo)` from your ViewModel permanently saves the data to the device disk, so it's still there even if you force-close and reopen the app.
Let's walk through it together
@Entity
data class TodoEntity(
@PrimaryKey val id: String,
val title: String,
val isDone: Boolean
)
@Dao
interface TodoDao {
@Query("SELECT * FROM TodoEntity")
suspend fun getAll(): List<TodoEntity>
@Insert
suspend fun insert(todo: TodoEntity)
}
@Database(entities = [TodoEntity::class], version = 1)
abstract class AppDatabase : RoomDatabase() {
abstract fun todoDao(): TodoDao
}Even after force-closing and reopening the app, you should see the todo list data still there (pulled back from Room).5-minute try-it
Write `TodoEntity`, `TodoDao`, and `AppDatabase` yourself, then rewrite `TodoViewModel` (Advanced lesson 1) to call the Room DAO instead of using an in-memory list.
A quick word of caution
Using `fallbackToDestructiveMigration()` in a production app instead of a proper `Migration` strategy when the database schema changes can wipe out all of an existing user's data after an update.