Udemy
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
Development
Web Development Data Science Mobile Development Programming Languages Game Development Database Design & Development Software Testing Software Engineering Development Tools No-Code Development
Business
Entrepreneurship Communications Management Sales Business Strategy Operations Project Management Business Law Business Analytics & Intelligence Human Resources Industry E-Commerce Media Real Estate Other Business
Finance & Accounting
Accounting & Bookkeeping Compliance Cryptocurrency & Blockchain Economics Finance Finance Cert & Exam Prep Financial Modeling & Analysis Investing & Trading Money Management Tools Taxes Other Finance & Accounting
IT & Software
IT Certification Network & Security Hardware Operating Systems Other IT & Software
Office Productivity
Microsoft Apple Google SAP Oracle Other Office Productivity
Personal Development
Personal Transformation Personal Productivity Leadership Career Development Parenting & Relationships Happiness Esoteric Practices Religion & Spirituality Personal Brand Building Creativity Influence Self Esteem & Confidence Stress Management Memory & Study Skills Motivation Other Personal Development
Design
Web Design Graphic Design & Illustration Design Tools User Experience Design Game Design Design Thinking 3D & Animation Fashion Design Architectural Design Interior Design Other Design
Marketing
Digital Marketing Search Engine Optimization Social Media Marketing Branding Marketing Fundamentals Marketing Analytics & Automation Public Relations Advertising Video & Mobile Marketing Content Marketing Growth Hacking Affiliate Marketing Product Marketing Other Marketing
Lifestyle
Arts & Crafts Beauty & Makeup Esoteric Practices Food & Beverage Gaming Home Improvement Pet Care & Training Travel Other Lifestyle
Photography & Video
Digital Photography Photography Portrait Photography Photography Tools Commercial Photography Video Design Other Photography & Video
Health & Fitness
Fitness General Health Sports Nutrition Yoga Mental Health Dieting Self Defense Safety & First Aid Dance Meditation Other Health & Fitness
Music
Instruments Music Production Music Fundamentals Vocal Music Techniques Music Software Other Music
Teaching & Academics
Engineering Humanities Math Science Online Education Social Science Language Teacher Training Test Prep Other Teaching & Academics
AWS Certification Microsoft Certification AWS Certified Solutions Architect - Associate AWS Certified Cloud Practitioner CompTIA A+ Cisco CCNA Amazon AWS AWS Certified Developer - Associate CompTIA Security+
Graphic Design Photoshop Adobe Illustrator Drawing Digital Painting InDesign Character Design Canva Figure Drawing
Life Coach Training Neuro-Linguistic Programming Mindfulness Personal Development Personal Transformation Life Purpose Meditation Emotional Intelligence Neuroscience
Web Development JavaScript React CSS Angular PHP WordPress Node.Js Python
Google Flutter Android Development iOS Development Swift React Native Dart Programming Language Mobile Development Kotlin SwiftUI
Digital Marketing Google Ads (Adwords) Social Media Marketing Google Ads (AdWords) Certification Marketing Strategy Internet Marketing YouTube Marketing Email Marketing Retargeting
SQL Microsoft Power BI Tableau Business Analysis Business Intelligence MySQL Data Analysis Data Modeling Big Data
Business Fundamentals Entrepreneurship Fundamentals Business Strategy Online Business Business Plan Startup Blogging Freelancing Home Business
Unity Game Development Fundamentals Unreal Engine C# 3D Game Development C++ 2D Game Development Unreal Engine Blueprints Blender
30-Day Money-Back Guarantee
Development Mobile Development Android Development

Mastering Kotlin Coroutines for Android Development

Learn how to implement 12+ of the most common use cases for Kotlin Coroutines on Android
Rating: 4.6 out of 54.6 (98 ratings)
488 students
Created by Lukas Lechner
Last updated 1/2021
English
English [Auto]
30-Day Money-Back Guarantee

What you'll learn

  • How to implement 12+ of the most common use cases for Kotlin Coroutines on Android.
  • Get a deep understanding of Kotlin Coroutines (Suspend Functions, Coroutine Builders, blocking vs suspending, Coroutines vs Threads).
  • Learn advanced Concepts (Structured Concurrency, Coroutine Scopes and Contexts, internal workings)
  • Understand the advantages of using Coroutines over Callbacks or RxJava.
  • How to perform network requests with Retrofit sequentially and concurrently.
  • How to use Room together with Coroutines.
  • How to do background processing with Coroutines.
  • How to appropriately deal with exceptions.
  • How to write Unit Tests for coroutine-based implementations.
  • How to implement Timeouts and Retries.

Course content

13 sections • 107 lectures • 9h 27m total length

  • Preview05:14
  • How to get the source code of the Sample Project
    03:04
  • Basic Setup of Sample Project
    12:42

  • Section Introduction
    01:28
  • Preview01:59
  • Use Case Explanation
    01:20
  • Callback Implementation
    11:05
  • RxJava Implementation
    06:11
  • Coroutines Implementation
    08:36
  • Comparing Approaches
    20:53
  • Recap
    02:07

  • Section Introduction
    01:39
  • Preview07:14
  • Preview04:09
  • Preview07:12
  • Preview07:21
  • Preview03:24
  • Preview06:24
  • Preview07:48
  • Section Recap
    02:47

  • Introduction
    01:08
  • Adding Coroutines to your project
    02:20
  • Coroutine Builders: Launch and RunBlocking
    18:28
  • Main-safety
    02:34
  • Basic error handling with try-catch
    03:15
  • Exercise 1
    02:30
  • Exercise 1: Solution
    01:55
  • Section Recap
    02:34

  • Section Introduction
    01:05
  • UseCase description
    02:25
  • Implementing UseCase#3 in a sequential way
    04:57
  • The async coroutine builder
    13:59
  • Implementing UseCase#3 in a concurrent way
    07:42
  • Implementing UseCase#4 in a sequential way
    05:10
  • Exercise 2: Implementing UseCase#4 in a concurrent way
    01:07
  • Exercise 2: Solution
    04:19
  • Section Recap
    01:27

  • Implementing a timeout
    08:43
  • Implementing retries
    04:27
  • Extract retry logic into higher order function
    07:02
  • Add exponential backoff to retry
    04:52
  • Exercise 3: Combining retries and timeout
    01:42
  • Exercise 3: Solution
    03:45
  • Section Recap
    01:01

  • Section Introduction
    01:23
  • UseCase description
    03:12
  • UseCase Implementation
    13:14
  • Section Recap
    01:04

  • Section Introduction
    01:05
  • UseCase explanation
    01:46
  • Implementation running on Main Thread
    06:27
  • Coroutine Context
    04:54
  • Preview06:48
  • Using withContext for context switching
    10:57
  • Coroutine Scope VS Coroutine Context
    02:07
  • Exercise4: Perform calculation in several Coroutines
    07:15
  • Exercise 4: Solution
    07:00
  • Performance Analysis
    01:56
  • Section Recap
    02:31

  • Section Introduction
    01:41
  • The unhappy path
    03:00
  • Preview08:26
  • Preview05:09
  • Building up the Job Hierarchy
    11:14
  • Parents wait for Children
    02:15
  • Cancellation of parent and child jobs
    05:26
  • Job and SupervisorJob
    05:28
  • Unstructured Concurrency
    04:45
  • GlobalScope
    03:48
  • ViewModelScope
    08:24
  • LifecycleScope
    03:08
  • Scoping Functions coroutineScope{} and supervisorScope{}
    09:49
  • Continue Coroutine execution when the user leaves the screen
    12:19
  • Section Recap
    05:04

  • Cancelling Coroutines
    05:03
  • Cooperative Cancellation
    06:02
  • NonCancellable Code
    02:11
  • Making UseCase10 cooperative regarding cancellation
    04:53
  • Section Recap
    02:34

Requirements

  • No prior knowledge about Kotlin Coroutines needed, however you should be familiar with the Basics of Kotlin and Android, as well as some Android Jetpack Components (ViewModels, LiveData, Room) and Retrofit.

Description

Google recommends Kotlin Coroutines as the preferred solution for asynchronous programming on Android. Sooner or later, probably every  Android developer will get in touch with them. This course will provide you with a deep understanding of Kotlin Coroutines and shows how to implement 12+ of the most common use cases for Android applications.


At first, we will take a detailed look at the advantages of Kotlin Coroutines over other approaches for asynchronous programming, like RxJava and Callbacks.


Then, we will talk about some theoretical fundamentals. These include:

  • Routines vs. Coroutines

  • Suspend Functions

  • Coroutines vs. Threads

  • Blocking vs. Suspending

  • Multithreaded Coroutines

  • Internal workings


Next, we will implement some of the most common use cases for Kotlin Coroutines in Android applications. These include: 

  • Performing network requests with Retrofit sequentially and concurrently

  • Implementing Timeouts and Retries

  • Using Room with Coroutines

  • Performing background processing with Coroutines

  • Continuing Coroutine execution even when the user leaves the screen.


To improve your learning experience, this course also challenges you with several exercises.


Learning Coroutines can be overwhelming because you need to learn a lot of new concepts. However, we are going to start simple and as our use cases will get more and more complex, we will learn about new concepts step-by-step. These new concepts are:

  • Coroutine Builders (launch, async, runBlocking)

  • Coroutine Context

  • Coroutine Dispatchers

  • Structured Concurrency

  • Coroutine Scopes (viewModelScope, lifecycleScope, GlobalScope)

  • Jobs and SupervisorJobs

  • scoping functions (coroutineScope{} and supervisorScope{})

  • Cooperative Cancellation

  • Non-Cancellable Code


We will also make a deep dive into Exception Handling and discuss concepts like: 

  • exception handling with try/catch

  • exception handling with CoroutineExceptionHandlers

  • when to use try/catch and when to use a CoroutineExceptionHandler

  • exception handling in Coroutines started with launch and async

  • exception handling specifics of scoping functions coroutineScope{} and supervisorScope{}


Unit Tests are very important for every codebase. In the final section of the course we will write unit tests for most of the coroutine-based use cases we implemented earlier. We will discuss concepts like

  • TestCoroutineDispatcher

  • creating a JUnit4 Rule for testing coroutine-based code

  • runBlockingTest{} Coroutine Builder

  • virtual time

  • Testing sequential and concurrent execution

  • TestCoroutineScope


By the end of this course, you will have a fundamental understanding of Kotlin Coroutines and are able to write readable and maintainable, asynchronous and multithreaded Android Applications.

Who this course is for:

  • Android Developers who want to get a deep understanding of Kotlin Coroutines and how to implement 12+ of the most common use cases on Android.

Featured review

Vimosanan Ahiladas
Vimosanan Ahiladas
15 courses
8 reviews
Rating: 5.0 out of 52 months ago
I have read a lot about coroutine in Kotlin Documentation as well as medium post and practiced a lot. This make me to recap everything and gave a confident of what my understanding about Coroutine is right. Further, I was trouble on writing test cases with LiveData and Coroutines. But now somehow I got it. Now I can move forwards with test cases... Thanks ☺️☺️☺️

Instructor

Lukas Lechner
Freelance Android Developer
Lukas Lechner
  • 4.6 Instructor Rating
  • 98 Reviews
  • 488 Students
  • 1 Course

Hi, I am Lukas.

I am a Software Developer with over 15 years of experience. I am currently working as a Freelance Android developer.

I have more than 6 years of professional experience as an Android Developer and worked on some of the biggest mobile app projects in Austria.

I am regularly writing articles for my blog and I regularly speak at international developer conferences.


Breaking down complex technical topics into understandable pieces and teaching them in a simple and approachable way is my big passion.


  • Udemy for Business
  • Teach on Udemy
  • Get the app
  • About us
  • Contact us
  • Careers
  • Blog
  • Help and Support
  • Affiliate
  • Terms
  • Privacy policy
  • Cookie settings
  • Sitemap
  • Featured courses
Udemy
© 2021 Udemy, Inc.