Hot vs. Cold Streams: StateFlow vs. Flow in Android

This tests your grasp of stream lifecycles. A great answer defines cold `Flow` (lazy, per-collector) vs. hot `StateFlow` (active, shared state) and uses a ViewModel UI state scenario. A red flag is mischaracterizing a `Flow` as a one-time operation.
This question tests your understanding of stream lifecycles and state management in Android. A strong answer first defines a cold `Flow` as lazy (starts on collection) and a hot `StateFlow` as active (exists without collectors). Then, it explains `StateFlow`'s role in holding the most recent state and providing it to new collectors, using a ViewModel exposing UI state as the prime example. A common red flag is failing to explain *why* a cold flow is wrong for UI state (e.g., re-fetching data on rotation).
Read the original → developer.android.com
- #kotlin
- #coroutines
- #android
- #flow
- #architecture
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.