Use these additional resources to learn even more about Kotlin coroutines and flow. These resources are grouped by topic.
Basics
- First things first:
This article teaches basic coroutine concepts, including
CoroutineScope
,Job
, andCoroutineContext
. - The ABC of coroutines: Learn about the most common classes and functions used when working with coroutines.
- Coroutines in Android (series - 1st article linked): This post is the first in a series that teaches you about Kotlin coroutines.
- Understand Kotlin Coroutines on Android: This Google I/O 2019 talk gives an overview of using Kotlin coroutines on Android.
- Coroutines codelab: This codelab shows you how to use Kotlin coroutines to manage background threads and simplify your async code.
- Coroutines: how to manage async tasks in Kotlin: Learn about the state of coroutines in Android as of 2020.
Cancellation
- Cancellation in coroutines: This article talks about about the ins and outs of coroutine cancellation.
- Coroutines: Gotta catch 'em all: Learn best practices for handling cancellation and exceptions in Kotlin coroutines.
Exceptions
- Exceptions in coroutines: Learn how exceptions are propagated in coroutines and how to handle them.
- Coroutines: Gotta catch 'em all: Learn best practices for handling cancellation and exceptions in Kotlin coroutines.
Scopes
- Easy coroutines in Android: viewModelScope:
This article describes
viewModelScope
, an extension property that adds coroutines support to theViewModel
class. - Patterns for work that shouldn't be cancelled:
This article describes how to trigger coroutines that shouldn't be
cancelled using an
applicationScope
orexternalScope
.
Flow
- Going with the Flow: Learn about the flow API and its benefits.
- Advanced Coroutines with Kotlin Flow and LiveData:
Learn how to use Kotlin coroutines with
LiveData
and flow in an Android app. - Lessons learnt using Coroutines Flow in the Android Dev Summit 2019 app: This article highlights best practices and other lessons learned when adding flow support to the Android Dev Summit 2019 app.
- Things to know about Flow's shareIn and stateIn operators:
This article talks about how the
stateIn
andshareIn
operators can be used to improve performance, or even as a caching mechanism. - Migrating from LiveData to Kotlin Flow: This article talks about what's the equivalent Flow code for some of the most common LiveData patterns you can have in your app. This helps if you're interested in migrating from LiveData to Flow.
Testing
- Testing coroutines on Android: Learn about the best practices to test your coroutines.
- Testing codelab - Coroutines section:
Learn about testing ViewModels that use coroutines by replacing
Dispatchers.Main
with aTestCoroutineDispatcher
. - Testing two consecutive LiveData emissions in Coroutines: Learn how to use
TestCoroutineDispatcher
to pause and resume the execution of coroutines.
Libraries, Jetpack, and Coroutines
- LiveData with Coroutines and Flow:
This talk from the 2019 Android Dev Summit covers how to use the
liveData
coroutine builder along with testing patterns and antipatterns to make clean, efficient, and solid reactive UIs. - Building a Kotlin extensions library: Learn how to build a Kotlin extensions library that adds coroutines and flow support to existing classes.
- Simplifying APIs with coroutines and Flow: Learn how to simplify your libraries with coroutine adapters, create your own, and see how they work under the hood.
Coroutines in the view layer
- Suspending over Views: This post talks about how coroutines can make UI programming easier.
Under the hood
- Suspend functions - Kotlin Vocabulary: Learn why coroutines are important and how they work under the hood.
- The suspend modifier under the hood: Learn how the compiler transforms your code to suspend and resume the execution of your coroutines.