Kotlin Flow3 min read

StateFlow vs SharedFlow: When to Use Which ⚡

Kotlin's Flow APIs are powerful, but many devs trip up on StateFlow vs SharedFlow. Both are hot flows, but they shine in different situations.

September 23, 2025By Divya

🔹 StateFlow

Holds a single up-to-date value (like LiveData).

Always has an initial value.

Collectors immediately get the latest state.

Perfect for UI state that needs to be observed continuously.

val uiState = MutableStateFlow(Loading)

👉 Use when you want your UI to always reflect the current state.

🔹 SharedFlow

No initial value.

Can replay a set number of past emissions.

Great for one-off events (navigation, toasts, error messages).

val events = MutableSharedFlow<UiEvent>()

👉 Use when you want to broadcast events without holding onto state.

TL;DR ⚡

StateFlow = state holder 🧠

SharedFlow = event broadcaster 📢

Think of it this way:

StateFlow: "What's the app's current mood?"

SharedFlow: "What just happened that the UI should react to?"

Key Differences Summary

FeatureStateFlowSharedFlow
Initial ValueAlways has oneNo initial value
Use CaseState managementEvent broadcasting
New CollectorsGet latest value immediatelyOnly get future emissions