Devii · Mobile · 2026-04-22 · 7 min read
Kotlin Coroutines On Android: Dispatchers, Scopes, And Main Safety
How kotlinx.coroutines maps to threads, why `Dispatchers.Main` matters, and structured concurrency in ViewModel code.
**Kotlin coroutines** are lightweight tasks scheduled on thread pools. On Android, `Dispatchers.Main` posts to the UI thread; `Dispatchers.IO` suits blocking I/O; `Dispatchers.Default` is for CPU work. The library is `kotlinx.coroutines`, documented on `kotlinlang.org`.
**Structured concurrency** ties coroutines to scopes (`viewModelScope`, `lifecycleScope`) so cancellation propagates when screens destroy. Leaked global scopes survive configuration changes and cause crashes or wasted battery.
Suspend functions compile to state machines; they do not block threads at suspension points. Blocking calls inside coroutines without shifting dispatchers can freeze the UI.
Google's architecture guidance recommends coroutines with Flow for reactive data. Read Android Developers docs for your chosen Jetpack version; APIs evolve between releases.