tezvyn:

Hot vs cold Kotlin Flows and StateFlow use case

Source: developer.android.comintermediate

Tests grasp of flow lifecycle and collector behavior. A strong answer contrasts cold Flows, which restart per collector, with hot StateFlows broadcasting to all observers. Red flag: using Flow for UI state without citing config changes or initial value.

Tests your grasp of Kotlin stream semantics and UI state ownership. A cold Flow restarts per collector, suiting one-shot loads, while hot StateFlow multicasts from one source to all observers. Choose StateFlow for ViewModel UI state since it always holds a value, survives config changes, and emits only on change. Strong answers note StateFlow needs an initial value and behaves like in-memory state. Red flag: recommending Flow for screen state without citing redundant work or lost emissions.

Read the original → developer.android.com

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.

Hot vs cold Kotlin Flows and StateFlow use case · Tezvyn