Coroutines & Suspend Functions
Write asynchronous code that reads like synchronous code. Use suspend functions, coroutine scopes, and dispatchers (IO, Main, Default).
The Problem: Blocking the UI Thread
Android runs all UI work on the main thread. If you do a network request or database read on the main thread, the UI freezes until it finishes.
If the UI freezes for more than 5 seconds, Android shows an ANR (App Not Responding) dialog and the user can force-close your app.
What Are Coroutines?
Kotlin Coroutines are a way to write asynchronous code that looks sequential — no callbacks, no RxJava chains.
- Lightweight — thousands of coroutines can run concurrently
- Suspendable — a coroutine can pause and resume without blocking a thread
- Structured — they respect a lifecycle (scope)
All lessons in this course
- ViewModel & LiveData
- Room Database
- Coroutines & Suspend Functions
- Repository Pattern
- Navigation Component
- Dependency Injection with Hilt