How apps work
Threads & concurrency
One main thread, a clever message queue, and twenty years of async.
5 pages55 min5 interactive7500 words
- 01The main threadEvery app process has one thread that does everything the user can see. Blocking it is not slow code — it is an unresponsive app, by definition.beginner11 mininteractive
- 02Looper, Handler, MessageQueueThree classes that have not changed in fifteen years: a thread-local loop, a priority queue ordered by due time, and the native epoll wait that lets an idle app consume nothing.nerd11 mininteractive
- 03AsyncTask, RxJava, coroutinesTwenty years of Android async in one line: every era's tool was a better way to say 'do this off the main thread, then come back'. None of them replaced the Looper.intermediate11 mininteractive
- 04Coroutines on AndroidA coroutine is not a thread. It is a state machine the compiler generates, dispatched onto a thread. That distinction explains cancellation, structured concurrency, and why suspension is cheap.intermediate11 mininteractive
- 05Threads in a real app processOpen any Android app in a profiler and you will find dozens of threads you never created. Knowing where they come from is the difference between a scary trace and a readable one.nerd11 mininteractive
Test yourself
Test yourself: Threads & concurrency
Put these async tools in the order they became the recommended way to do background work on Android.
Drag, or use the arrows to reorder.
- 1Handler and Thread
- 2Kotlin coroutines
- 3AsyncTask
- 4RxJava