Learn Coroutines in Kotlin and Android!
Executing background tasks has always been a big challenge in every environment and, in particular, on mobile devices where resources are limited. Kotlin has simplified the way you can write code improving your productivity with a new programming paradigm, enhancing object-oriented and functional programming with with simple, powerful and new constructs. Coroutines are one of these!
Who This Book Is For
This book is for intermediate Kotlin or Android developers who already know the basics of UI development but want to learn coroutine API in order to simplify and optimize their code.
Topics Covered in This Book
Asynchronous programming: Learn what asynchronous programming means and how to achieve it using not blocking calls.
Configuration: Learn how to configure IntelliJ and Android Studio in order to use Coroutine APIs.
Coroutine principles**: Learn what coroutines and launching builders are and how to manage Job dependencies.
Suspending functions: This is the main concept around coroutines and you'll learn how to declare a suspending function and how to deal with results.
Sequences and Iterators: Learn how to manage theoretically infinite collections of data in an efficient way using Sequences, Iterators and the yield function.
Thread communication techniques**: Learn how different tasks can communicate using Channels, Actors, and specific coroutine operators.
And much more, including benchmarks, Broadcast Channels, State machines!
One thing you can count on: After reading this book, you’ll be prepared to take advantage of all the improvements coroutines have to offer!
About the Tutorial Team
The Tutorial Team is a group of app developers and authors who write tutorials at the popular website raywenderlich.com. We take pride in making sure each tutorial we write holds to the highest standards of quality. We want our tutorials to be well written, easy to follow, and fun. If you've enjoyed the tutorials we've written in the
AI Reading Assistant
Whole-book reading guide from stratified index samples; jump to passages in the text
Tip the Site
Support this siteYour recognition and a small knowledge-service contribution help keep this technical work open source.Scan the WeChat Pay or Alipay code below. Logged-in and guest visitors can both tip.
WeChat Pay
Alipay
Open WeChat or Alipay and scan. No login required.
AI guide
【One-Line Pitch】
A hands-on, tutorial-driven guide for intermediate Kotlin/Android developers who want to master coroutines—from basic builders and suspending functions to advanced patterns like async/await, channels, and lifecycle-aware Android integration—so you can write cleaner, non-blocking background code.
【Book Arc】
- **Opening (~0%–9%)**: Introduces the core problem of asynchronous programming—blocking calls that freeze UI—using a simple image-upload example to show why traditional sequential code fails. Sets up the book’s promise: coroutines as a modern, lightweight solution.
- **Early (~9%–25%)**: Explains coroutine fundamentals: what they are (a 1960s mechanism revived), how suspension points and continuations work, and how to set up your environment (JDK 1.8, IntelliJ, Android Studio). Covers the first builders (`launch`, `Job`), scopes, and basic cancellation.
- **Early-to-Middle (~25%–38%)**: Dives into suspending functions—the heart of coroutines. Shows how to convert blocking callbacks into suspendable code, handle happy/unhappy paths with `try/catch`, and build your own suspendable APIs using `suspendCoroutine()` and `Result`.
- **Middle (~38%–47%)**: Explores the `async`/`await` pattern, comparing it to JavaScript promises and Java futures. Emphasizes structured concurrency and cooperative cancellation—why child coroutines should respect parent state, and how to avoid wasted work.
- **Late (~47%–60%+)**: Moves to advanced topics: sequences and iterators for infinite data, channels and actors for thread communication, plus benchmarks, broadcast channels, and state machines. The final chapters (per the table of contents) apply everything to Android—debugging, exception handling, testing, and lifecycle integration.
【Key Takeaways】
- **Blocking calls are the root of UI jank** (Opening): A spinner animation can’t run while an upload blocks the thread; coroutines solve this by suspending instead of blocking. This motivates the entire book.
- **Coroutines are part-thread, part-callback** (Early): They use suspension points and continuations to return results without callbacks or threads, letting you write sequential-looking code that runs asynchronously.
- **`launch` and `Job` are your building blocks** (Early): `launch` starts a coroutine and returns a `Job` you can cancel, join, or nest. Always check `isActive` during computational work to keep code cooperative.
- **Suspending functions are the core abstraction** (Early-to-Middle): Mark a function `suspend` to offload work to background threads while keeping the call site sequential and exception-friendly—no callback hell.
- **`async`/`await` enables value-returning concurrency** (Middle): `async` wraps a call in a `Deferred`, and `await` suspends until the value is ready. This pattern is cleaner than promises for multithreaded Android apps.
- **Structured concurrency prevents wasted work** (Middle): If a parent coroutine is canceled, children should cancel too—but only if you write cooperative code that checks `isActive` and respects scope.
- **Channels and actors enable safe thread communication** (Late): These primitives let different coroutines exchange data without shared-memory races, essential for complex background pipelines.
- **Android integration requires lifecycle awareness** (Late): Coroutines must be tied to UI lifecycles (e.g., via `Dispatchers.Main` and scope management) to avoid leaks and crashes; testing and debugging require special attention.
【Reading Tips】
- **Skim the environment setup (Chapter 2)** if you already have IntelliJ/Android Studio; just note the JDK 1.8 requirement for Android compatibility.
- **Deep-read Chapters 3–5** (Getting Started, Suspending Functions, Async/Await)—these are the conceptual core. Work through every code example, especially the cancellation and structured-concurrency scenarios.
- **Pay extra attention to the "cooperative code" examples** (around 44–47%): they show the subtle difference between correct and incorrect cancellation, a common real-world pitfall.
- **Treat the Android chapters (17–18) as a capstone**: they tie everything together with debugging, exception handling, and testing—skim if you’re not doing Android, but read fully if you are.
- **Don’t skip the "Key points" summaries** at each chapter’s end; they’re excellent for review and quick reference before writing your own code.
【Coverage Limits】
This guide synthesizes the first ~47% of the book in detail (fundamentals through async/await); the later sections on sequences, channels, actors, and Android-specific chapters are summarized from the table of contents and may lack depth if you need those specifics.
Excerpt 1
ho write tutorials at the popular website raywenderlich.com. We take pride in making sure each tutorial we write holds to the highest standards of quality. W...
s it to a thread pool, where it waits for further commands. Once you’re ready to eat the taco and you request the result, the program can block until you get...
ity available and a bit more clean, programmers define the callback as a two-parameter lambda, with the first being the value, if there is any, and the secon...
re four main dispatchers: Default, IO, Main and Unconfined. • Using the Executors class you can create new thread pools to use for your coroutine work. raywe...
a thread is a unit of execution, lighter in weight than a process, generally expected to share memory and other resources with other threads executed concurr...
Support this siteYour recognition and a small knowledge-service contribution help keep this technical work open source.
Scan the WeChat Pay or Alipay code below. Logged-in and guest visitors can both tip.
WeChat PayAlipay
Open WeChat or Alipay and scan. No login required.
Add Tag
Enter tag name (max 50 characters)
Share E-Book
Kotlin Coroutines by Tutorial Mastering Coroutines in Kotlin and Android (raywenderlich Tutorial Team, Filip Babić etc.)(Z-Library)
Scan QR code with your phone to access
Copy the link or scan the QR code to access this e-book on your phone
Share E-Book via Email
Please enter email address
Donation Statistics
¥.00
Total Donations
0
Donation Count
Kotlin Coroutines by Tutorial Mastering Coroutines in Kotlin and Android (raywenderlich Tutorial Team, Filip Babić etc.)(Z-Library)
Find Your Favorite Books
Only registered users can comment after logging in. Comments need to be reviewed by administrators before being displayed
Loading comments...
Reply to Comment
Edit Comment