Simplifying Android Development with Coroutines and Flows: Learn how to use Kotlin coroutines and the flow API to handle data streams asynchronously in your Android app
- Length: 164 pages
- Edition: 1
- Language: English
- Publisher: Packt Publishing
- Publication Date: 2022-07-27
- ISBN-10: 1801816247
- ISBN-13: 9781801816243
- Sales Rank: #2491729 (See Top 100 Books)
Get to grips with asynchronous programming in Android using simple, modern, and testable code through Kotlin coroutines and flow
Key Features
- Find out how to improve app performance with Kotlin coroutines
- Discover the new recommended ways to use Kotlin coroutines and flows
- Learn the basics of asynchronous programming, along with an overview of coroutines and flow
Book Description
Coroutines and flows are the new recommended way for developers to carry out asynchronous programming in Android using simple, modern, and testable code. This book will teach you how coroutines and flows work and how to use them in building Android applications, along with helping you to develop modern Android applications with asynchronous programming using real data.
The book begins by showing you how to create and handle Kotlin coroutines on Android. You’ll explore asynchronous programming in Kotlin, and understand how to test Kotlin coroutines. Next, you’ll learn about Kotlin flows on Android, and have a closer look at using Kotlin flows by getting to grips with handling flow cancellations and exceptions and testing the flows.
By the end of this book, you’ll have the skills you need to build high-quality and maintainable Android applications using coroutines and flows.
What you will learn
- Understand how coroutines and flows differ from existing ways
- Apply asynchronous programming in Android with coroutines and flows
- Find out how to build your own coroutines and flows in Android
- Handle, manipulate, and combine data in coroutines and flows
- Handle cancellations and exceptions from coroutines and flows
- Discover how to add tests for your coroutines and flows
- Integrate coroutines and flows into your Android projects
Who this book is for
This book is for intermediate-level Android developers who want to level up their Android app-building skills. Familiarity with Android development and basic knowledge of Kotlin are needed to make the most of this book.
Simplifying Android Development with Coroutines and Flows Foreword Contributors About the author About the reviewer Preface Who this book is for What this book covers To get the most out of this book Download the example code files Conventions used Get in touch Share Your Thoughts Part 1 – Kotlin Coroutines on Android Chapter 1: Introduction to Asynchronous Programming in Android Technical requirements Understanding asynchronous programming Exploring threads, AsyncTasks, and Executors Threads Callbacks AsyncTask Executors The new way to do it – coroutines and flows Kotlin coroutines Kotlin Flows Summary Further reading Chapter 2: Understanding Kotlin Coroutines Technical requirements Creating coroutines in Android Exploring coroutine builders, scopes, and dispatchers Coroutine builders Coroutine scopes Coroutine dispatchers Understanding coroutine contexts and jobs Coroutine contexts Coroutine jobs Exercise – using coroutines in an Android app Summary Chapter 3: Handling Coroutine Cancelations and Exceptions Technical requirements Canceling coroutines Exercise 3.01 – canceling coroutines in an Android app Managing coroutine timeouts Catching exceptions in coroutines Exercise 3.02 – catching exceptions in your coroutines Summary Chapter 4: Testing Kotlin Coroutines Technical requirements Setting up an Android project for testing coroutines Unit testing suspending functions Testing coroutines Exercise 4.01 – adding tests to coroutines in an Android app Summary Further reading Part 2 – Kotlin Flows on Android Chapter 5: Using Kotlin Flows Technical requirements Using Flows in Android Creating Flows with Flow builders Using operators with Flows Collecting Flows with terminal operators Transforming Flows with Intermediate operators Buffering and combining flows Buffering Kotlin Flows Combining Flows Exploring StateFlow and SharedFlow Exercise 5.01 – Using Kotlin Flow in an Android app Summary Chapter 6: Handling Flow Cancelations and Exceptions Technical requirements Canceling Kotlin Flows Retrying tasks with Flow Catching exceptions in Flows Handling Flow completion Exercise 6.01 – Handling Flow exception in an Android app Summary Chapter 7: Testing Kotlin Flows Technical requirements Setting up an Android project for testing Flows Testing Kotlin Flows Testing Flows with Turbine Exercise 7.01 – Adding tests to Flows in an Android app Summary Why subscribe? Other Books You May Enjoy Packt is searching for authors like you Share Your Thoughts
Donate to keep this site alive
How to download source code?
1. Go to: https://github.com/PacktPublishing
2. In the Find a repository… box, search the book title: Simplifying Android Development with Coroutines and Flows: Learn how to use Kotlin coroutines and the flow API to handle data streams asynchronously in your Android app
, sometime you may not get the results, please search the main title.
3. Click the book title in the search results.
3. Click Code to download.
1. Disable the AdBlock plugin. Otherwise, you may not get any links.
2. Solve the CAPTCHA.
3. Click download link.
4. Lead to download server to download.