Observing Data with Flow
React to database changes reactively.
Reactive Database Reads
Instead of querying once, Room can return a Flow that emits a new value every time the underlying data changes. Your UI updates automatically.
Returning a Flow from a DAO
Declare the return type as Flow<...>. Notice it is not a suspend function.
@Query("SELECT * FROM users ORDER BY name")
fun observeUsers(): Flow<List<User>>All lessons in this course
- Entities and DAOs
- The Room Database Class
- Queries and Relationships
- Observing Data with Flow