Kotlin Coroutines by Tutorials
Android is inherently asynchronous and event-driven, with strict requirements as to on which thread certain things can happen. Learn how to use Kotlin coroutines to solve common Android programming problems using asynchronous programming techniques! By Luka Kordić & Filip Babić.
Who is this for?
This book is for intermediate Kotlin or Android developers who already know the basics of UI development but want to learn coroutine API to simplify and optimize their code.
- Asynchronous programming
- Coroutine principles
- Suspending functions
- Sequences & Iterators
- Thread communication techniques
The importance of concurrency is discovered quite early on by people who start with Android development. Android is inherently asynchronous and event-driven, with strict requirements as to on which thread certain things can happen.
Add to this the often-cumbersome Java callback interfaces, and you will be trapped in spaghetti code...more
Before You Begin
This section tells you a few things you need to know before you get started, such as what you’ll need for hardware and software, where to find the project files for this book, and more.
Section I: Introduction to Coroutines
In the first chapter, you’ll learn about the problems related to multithreading and how coroutines can be an elegant solution. After setting up your development environment in IntelliJ or Android Studio, you’ll start writing your first coroutine to understand what suspending functions are and how to define them. You’ll finish this section learning how to use async and await functions for efficient use of resources.
Section II: Channels & Flows
Coroutines provide you a set of suspending functions and coroutine builders for the most common use cases. In order to use them, you need to know some more details on how they work under the hood. In this section, you’ll explore channels, Coroutine Flow and testing your coroutines.
Section III: Coroutines & Android
Coroutines are becoming a very important tool for any Kotlin application and in particular for Android applications. They allow the creation of applications that are more readable and use simpler code. In this section, you’ll learn how to use coroutines as a valid option for running background tasks which interact with the UI thread.