Challenge - 5 Problems
Room Flow Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What happens when you collect a Flow from Room DAO?
You have a Room DAO function returning
Flow<List<User>>. What is the behavior when you collect this Flow in your UI?Android Kotlin
interface UserDao {
@Query("SELECT * FROM users")
fun getAllUsers(): Flow<List<User>>
}Attempts:
2 left
💡 Hint
Think about how Flow works with Room to provide live updates.
✗ Incorrect
Room integrates with Kotlin Flow to emit new data whenever the database table changes, so the UI updates automatically.
❓ lifecycle
intermediate2:00remaining
How to safely collect a Room Flow in an Android Activity?
You want to collect a Flow from Room in an Activity to update UI. Which lifecycle-aware approach is best?
Attempts:
2 left
💡 Hint
Consider Android lifecycle and coroutine scopes.
✗ Incorrect
Using lifecycleScope.launchWhenStarted ensures collection happens only when Activity is started and cancels automatically.
📝 Syntax
advanced2:00remaining
What is the correct DAO function signature for a Flow query?
Choose the correct Kotlin function signature for a Room DAO that returns a Flow of a list of entities named Item.
Attempts:
2 left
💡 Hint
Think about the type that represents a stream of lists.
✗ Incorrect
The correct signature returns a Flow emitting lists of Item objects, not a list of Flows or other types.
🔧 Debug
advanced2:00remaining
Why does collecting a Room Flow not emit updates?
You collect a Flow from Room DAO but the UI never updates after initial data. What is a likely cause?
Android Kotlin
val usersFlow = userDao.getAllUsers()
lifecycleScope.launchWhenStarted {
usersFlow.collect { users ->
adapter.submitList(users)
}
}Attempts:
2 left
💡 Hint
Consider what triggers Flow emissions from Room.
✗ Incorrect
Room emits new Flow data only when the underlying table changes. If no changes happen, no new emissions occur.
🧠 Conceptual
expert2:00remaining
How does Room with Flow handle backpressure and cancellation?
When collecting a Flow from Room, how does Room handle backpressure and cancellation to avoid resource leaks?
Attempts:
2 left
💡 Hint
Think about how Flow and Room cooperate with coroutine cancellation.
✗ Incorrect
Room integrates with Kotlin Flow to cancel queries automatically when the collector cancels, preventing leaks and handling backpressure.