Development mode — payments are simulated and emails go to the Dev Mailbox · Payment simulator
DDSP
Cover Kotlin Coroutines and Flow for Android — page spread 1 Kotlin Coroutines and Flow for Android — page spread 2 Kotlin Coroutines and Flow for Android — page spread 3 Kotlin Coroutines and Flow for Android — page spread 4 Kotlin Coroutines and Flow for Android — page spread 5 Kotlin Coroutines and Flow for Android — page spread 6 Kotlin Coroutines and Flow for Android — page spread 7 Kotlin Coroutines and Flow for Android — sample page Kotlin Coroutines and Flow for Android — sample page Kotlin Coroutines and Flow for Android — sample page

Master Kotlin coroutines and Flow on Android: suspend functions, builders, scopes, dispatchers, structured concurrency, cancellation and exceptions, supervision, Mutex and channels, Flow operators, StateFlow and SharedFlow, stateIn and shareIn, callbackFlow, Compose collection, Room, Retrofit…

Structured Concurrency, Cancellation, StateFlow and SharedFlow, Operators, Lifecycle-Aware Collection, and Testing

Read before you buy: the PDF here is a free sample — the first 20 pages of the 455-page book (payments, sales and reviews on this demo site are sample data). Get the full e-book at thenexbooks on Gumroad.

Stop copy-pasting viewModelScope.launch — understand what your coroutines are doing and write async Android code that cleans up after itself.

Almost every Kotlin Android app uses coroutines and Flow, and most of the hard bugs come from using them without a clear mental model: screens that keep updating after they are gone, search boxes that fire a request per keystroke, swallowed cancellation, listeners that are never unregistered, and tests that are slow or flaky. This book gives you the model first — which coroutine runs this code, on which dispatcher, who its parent is, and whether a stream is cold or hot — and then the code, so those bugs become easy to spot.

Written for Android developers who know Kotlin and have built a simple app, it does not re-teach Kotlin syntax or Compose layout. Instead you build the coroutine core of one realistic app step by step, with a starter project you can run and tests that use virtual time, so every timing in the book is exact and repeatable.

What's inside

  • Why coroutines: from callbacks and threads to suspend functions, and what suspension really means
  • Bridging one-shot callbacks with suspendCancellableCoroutine, and main-safety as a contract
  • launch, async, runBlocking, coroutineScope, CoroutineContext, and dispatchers (Main, IO, Default, limitedParallelism)
  • Structured concurrency: jobs, parents and children, viewModelScope, lifecycleScope, and application-wide scopes
  • Cancellation, timeouts, cleanup with NonCancellable, and why you must never swallow CancellationException
  • Exception propagation, CoroutineExceptionHandler, retry with exponential backoff, and supervision for partial failure
  • Shared mutable state with Mutex, Semaphore, atomics, and confinement; pipelines and fan-out with channels and select
  • Flow from the ground up: builders, terminal operators, map, filter, transform, scan, zip, combine, merge, and the flatMap family
  • Flow context and errors: flowOn, catch, retry, onCompletion, and exception transparency
  • Backpressure: buffer, conflate, collectLatest, debounce, and sample — with measured examples
  • Hot streams: SharedFlow for events, StateFlow for UI state, and stateIn and shareIn with SharingStarted.WhileSubscribed
  • callbackFlow and channelFlow for location updates and other listener APIs
  • ViewModels, UI state and one-off events, collectAsStateWithLifecycle, repeatOnLifecycle, and Compose effects
  • Room and DataStore flows, Retrofit suspend services in an offline-first repository, CoroutineWorker, and a foreground recording service
  • Testing with kotlinx-coroutines-test (runTest, test dispatchers, virtual time, backgroundScope) and Turbine
  • Debugging coroutines and a catalog of the most common mistakes, with fixes

One running example, start to finish. You build the coroutine core of Waypoint, a fictional hiking trip planner from a small studio called Northbeam Labs. Waypoint searches trails offline-first, records a hike from a stream of location fixes, keeps running totals of distance, elevation gain, and time, reminds the hiker after three hours on the move, and uploads recorded points in batches with retries. A starter project with a fake backend and simulated latency lets you run every example — no real server, account, or device required for the tests.

Current and honest. The code was written and tested with kotlinx.coroutines 1.11.0, Kotlin 2.4.20, and current stable Jetpack libraries at the time of writing. APIs still marked experimental or preview are labeled as such, timings come from virtual-time tests rather than invented benchmarks, and there are no made-up statistics. Every chapter includes Kotlin code, Tips, Notes, Warnings, exercises, and Key Takeaways, and the appendices give you a cheat sheet, copy-ready templates, a production checklist, and a glossary.

Format: PDF, 455 pages (A4), linked table of contents and bookmarks. English. First Edition, 2026. Published by thenexbooks. Includes the Waypoint starter project (Gradle, Kotlin) used throughout the book. Requires JDK 21 and the Android SDK (Android Studio recommended) to build the code. Requires Android Studio or another Kotlin/Gradle setup to run the examples. Android and Jetpack Compose are trademarks of Google LLC; Kotlin is a trademark of the Kotlin Foundation. This book is independent and is not affiliated with, sponsored by, or endorsed by Google, JetBrains, or the Kotlin Foundation.

Table of Contents

Part I — Coroutine Foundations

  • Ch 1 · Why Coroutines: From Callbacks and Threads to Suspend Functions
  • Ch 2 · Suspend Functions in Depth: Suspension Points, Continuations, and Bridging Callbacks
  • Ch 3 · Coroutine Builders: launch, async, runBlocking, and coroutineScope
  • Ch 4 · Dispatchers and Threads: Main, IO, Default, and withContext
  • Ch 5 · Structured Concurrency: Jobs, Scopes, viewModelScope, and lifecycleScope

Part II — Cancellation, Errors, and Coordination

  • Ch 6 · Cancellation: Cooperative Checks, Timeouts, and Cleanup
  • Ch 7 · Exceptions: Propagation, CoroutineExceptionHandler, and Error Strategies
  • Ch 8 · Supervision and Partial Failure: SupervisorJob and supervisorScope
  • Ch 9 · Shared Mutable State: Mutex, Semaphore, Atomics, and Confinement
  • Ch 10 · Channels: Producers, Consumers, Fan-Out, and select

Part III — Flow Fundamentals

  • Ch 11 · Flow Basics: Cold Streams, Builders, and Terminal Operators
  • Ch 12 · Transforming Flows: map, filter, transform, and Friends
  • Ch 13 · Combining Flows: zip, combine, merge, and the flatMap Family
  • Ch 14 · Flow Context and Errors: flowOn, catch, retry, and onCompletion
  • Ch 15 · Backpressure: buffer, conflate, collectLatest, debounce, and sample

Part IV — Hot Flows and State

  • Ch 16 · Cold vs Hot: SharedFlow for Events and Broadcasts
  • Ch 17 · StateFlow: Observable State for the UI Layer
  • Ch 18 · stateIn and shareIn: Sharing Upstream Work with SharingStarted
  • Ch 19 · callbackFlow and channelFlow: Bridging Location Updates and Other Callback APIs

Part V — Coroutines in the Android Stack

  • Ch 20 · ViewModels and UI State: Loading, Errors, and One-Off Events
  • Ch 21 · Collecting Safely: collectAsStateWithLifecycle, repeatOnLifecycle, and Compose Effects
  • Ch 22 · Room and DataStore with Coroutines and Flow
  • Ch 23 · Retrofit and Offline-First Repositories
  • Ch 24 · Background Work: CoroutineWorker, Foreground Services, and Long-Running Recording

Part VI — Testing, Debugging, and Production

  • Ch 25 · Testing Coroutines: runTest, Test Dispatchers, and Virtual Time
  • Ch 26 · Testing Flows with Turbine
  • Ch 27 · Debugging Coroutines and the Most Common Mistakes
  • Ch 28 · Case Study: The Waypoint Recording Pipeline End to End

Appendices
A · Coroutines and Flow Cheat Sheet
B · Templates and Reference
C · Production Checklist
D · Glossary

Book details

Detail
Pages455
FormatPDF (A4) + Waypoint starter project (Gradle)
LanguageEnglish
LevelIntermediate
Edition1st Edition (2026)
Download on this siteFree sample, first 20 pages (PDF)
Publisherthenexbooks

Files you get

PDF
Kotlin-Coroutines-and-Flow-for-Android-Free-Sample.pdf
648.1 KB · version 1 · updated 7 Aug 2026

No reviews yet. Only buyers can review.

More from thenexbooks

Visit store
$9.00