StateFlow & SharedFlow

KOTLIN › Concurrency

Hot Kotlin flows for UI state versus one-off events, collected lifecycle-safely.

Interviewers use StateFlow and SharedFlow to test whether you can model UI state separately from one-time events and collect both without leaking work or crashing. Expect to defend why StateFlow needs an initial value and conflates, why SharedFlow fits navigation and snackbar events, and how repeatOnLifecycle / collectAsStateWithLifecycle replace the discouraged launchWhenStarted. It is a frequent staff-level discriminator because the wrong choice causes lost events, duplicate dialogs, or wasted background work.

What this covers

Study this topic

Further reading