Predict the output
A screen observes note 1. Another screen edits note 2. Does the first flow emit?
@Dao
interface NoteDao {
@Query("SELECT * FROM notes WHERE id = :id")
fun observe(id: Long): Flow<NoteRow?>
@Query("UPDATE notes SET text = :text WHERE id = :id")
suspend fun rename(id: Long, text: String)
}Hint 1 of 1
What does Room track: rows or tables?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A Yes, with the same value, because invalidation is per table
Correct. Any write to notes re-runs the query.
Why not the others?
- B No, because note 1 didn't change. Room doesn't track rows, only tables.
- C Only if you call refresh(). Room flows update by themselves.
- D It throws because two screens observe the same table. Many observers are fine.