Hot vs. Cold Streams: `StateFlow` vs. `Flow`

Tests your grasp of stream lifecycles. A great answer defines cold `Flow` (lazy, per-collector) vs. hot `StateFlow` (shared, active), then uses a ViewModel UI state scenario to show why `StateFlow` is correct for surviving configuration changes.
This question tests your understanding of stream lifecycles and resource management, not just definitions. A strong answer first differentiates a cold `Flow` (a lazy blueprint creating a new stream per collector) from a hot `StateFlow` (an active, shared broadcast that holds state). Then, it applies this to a `ViewModel` exposing UI state. `StateFlow` is ideal because it survives configuration changes and provides the last state to the new UI instantly.
Read the original → developer.android.com
- #android
- #kotlin
- #coroutines
- #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.