Recall & Review
beginner
What is Flow in Kotlin and why is it useful with Room?
Flow is a Kotlin type that can emit multiple values sequentially. It is useful with Room because it allows your app to reactively observe database changes and update the UI automatically.
Click to reveal answer
beginner
How do you define a DAO method to return reactive data using Flow?
In your DAO interface, declare a function that returns
Flow<List<Entity>> instead of a direct list. For example: @Query("SELECT * FROM users") fun getUsers(): Flow<List<User>>Click to reveal answer
intermediate
What happens when the data in the Room database changes if you use Flow?
The Flow automatically emits the new data to all collectors. This means your UI or other parts of the app get updated data without manual refresh calls.
Click to reveal answer
intermediate
How do you collect data from a Flow in a ViewModel?
You can collect the Flow inside a coroutine scope, often using
viewModelScope.launch. Then you update a LiveData or StateFlow to expose data to the UI.Click to reveal answer
advanced
Why is using Flow with Room better than returning LiveData?
Flow is more flexible and supports many operators for data transformation. It integrates well with Kotlin coroutines and allows better control over threading and cancellation.
Click to reveal answer
Which return type should a DAO method use to provide reactive streams of data?
✗ Incorrect
Flow
- > allows the DAO to emit updates reactively whenever the data changes.
What Kotlin feature does Flow work with to handle asynchronous data streams?
✗ Incorrect
Flow is built on Kotlin coroutines to provide asynchronous and reactive data streams.
How do you start collecting data from a Flow in a ViewModel?
✗ Incorrect
You collect Flow inside a coroutine launched in viewModelScope to safely handle lifecycle and threading.
What happens if the Room database data changes when using Flow?
✗ Incorrect
Flow emits new data automatically when the database changes, enabling reactive UI updates.
Which of these is NOT an advantage of using Flow with Room?
✗ Incorrect
Flow automatically updates collectors; manual UI refresh is not needed.
Explain how Room and Flow work together to provide reactive data updates in an Android app.
Think about how data changes in the database reach the UI without manual refresh.
You got /4 concepts.
Describe the steps to collect data from a Room Flow in a ViewModel and expose it to the UI.
Focus on coroutine usage and data exposure patterns.
You got /4 concepts.