Coroutines Basics
KOTLIN › Concurrency
How suspend, builders, scopes, and dispatchers run async work without blocking threads.
Coroutines are the default concurrency model on modern Android, so interviewers probe whether you truly understand suspension versus blocking rather than just memorizing API names. Expect to explain what suspend compiles to, the difference between launch and async, and how dispatchers and withContext move work between threads. Strong answers connect these primitives to structured concurrency and main-safety.
What this covers
- What suspend actually does: pauses the coroutine without blocking the thread, via compiler CPS transformation
- launch returns a Job (fire-and-forget); async returns a Deferred whose await() retrieves the result
- Coroutine builders (launch, async, runBlocking, coroutineScope) and which thread/scope they run in
- CoroutineScope, structured concurrency, and how scope cancellation propagates to children
- Choosing dispatchers: Main for UI, IO for blocking I/O, Default for CPU work, Unconfined for advanced cases
- Using withContext to switch dispatchers and write main-safe suspend functions
Study this topic
- Coroutines Basics explained: the guided lesson
- 14 practice quiz questions
- 9 revision flashcards
- Coroutines Basics interview questions and answers