StateFlow & SharedFlow

KOTLIN › Flow

Hot flows for UI state versus one-off events, and why a Channel is often the better event bus.

Interviewers use StateFlow and SharedFlow to test whether you can model UI state separately from one-time events. Expect to defend why StateFlow needs an initial value and conflates, why that conflation makes it actively wrong for events, and what replay and extraBufferCapacity buy you. A strong answer goes further and admits SharedFlow is an imperfect event bus at either replay setting, reaching for a Channel with receiveAsFlow when a single screen consumes one-off events.

What this covers

Study this topic

Further reading