How it works
A suspend function can pause at a slow call and resume later without blocking a thread, so asynchronous code reads top to bottom like ordinary code instead of nested callbacks. Coroutines run in scopes tied to a lifetime, such as viewModelScope for a screen's ViewModel, and are cancelled automatically when that scope ends (structured concurrency). Dispatchers choose where work runs: Main for the interface, IO for disk and network.
Flow is a stream of values over time: a Room query that re-emits when rows change, search results as the user types, a download's progress. StateFlow holds the current UI state that Compose screens observe. Both come from JetBrains' kotlinx.coroutines library, work in Kotlin Multiplatform, and have largely replaced callbacks and RxJava in new Android code.
Coroutines and Flow pricing
Related terms
More in Mobile apps
Android building blocks