Mô tả

Google recommends Kotlin Coroutines and Flow as the preferred solution for asynchronous programming on Android. Sooner or later, probably every  Android developer will get in touch with these topics.


This course will give you a deep understanding of Kotlin Coroutines and Flow and show how to implement the most common use cases for Android applications.


This course consists of two big parts: The Coroutines part and the Flow part.

Before being able to use Flows in our applications, we first need a solid understanding of Coroutines. That’s why Coroutines are covered first. However, if you already have some experience with Coroutines, then you can also start with the Flow part right away, and jump back to lessons of the Coroutines part whenever needed.


In the part about Coroutines, 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 course's final section, 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


In the part about Kotlin Flow, we first cover all the basics. We will answer the question “What is a Flow?” and then we discuss the benefits and drawbacks of reactive programming.


Afterward, we are going to have a look at different Flow builders and operators:

  • basic flow builders

  • terminal operators

  • terminal operator “launchIn()”

  • terminal operator “asLiveData()”

  • lifecycle operators

  • intermediate operators


In our first real Flow use case, we use a Flow to create a live stock-tracking feature, that uses all the available basic flow components.


In the next module, we will take a look at Exception Handling and Cancellation with Kotlin Flow.


In the following module, you will learn about StateFlow and SharedFlow and the following concepts:

  • how to make Coroutines lifecycle-aware with the “repeatOnLifecycle()” suspend function

  • Hot Flows VS Cold Flows

  • Converting Flows to SharedFlows with the “shareIn()” operator

  • Converting Flows to StateFlows with the “stateIn()” operator

  • When to use SharedFlow and when to use StateFlow


Next, you will learn about Channels, how they differ from hot flows, and when they are useful in Android Applications.


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

Bạn sẽ học được gì

Yêu cầu

Nội dung khoá học

18 sections

Introduction

4 lectures
Extended Course Preview
05:49
Course Structure and Goals
09:34
How to get the source code of the Sample Project
03:04
Basic Setup of Sample Project
12:42

Different Approaches for Asynchronous Programming

8 lectures
Section Introduction
01:28
What is Asynchronous Programming?
01: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

Coroutine Fundamentals

9 lectures
Section Introduction
01:39
Routines and Coroutines
07:14
Suspend Functions
04:09
Coroutines and Threads
07:12
Blocking VS Suspending
07:21
Multithreaded Coroutines
03:24
Internal Workings
06:24
How delay() works
07:48
Section Recap
02:47

Performing Network Requests sequentially

8 lectures
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

Performing Network Requests concurrently

9 lectures
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

Higher-Order Functions

7 lectures
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

Using Room with Coroutines

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

Background Processing with Coroutines

11 lectures
Section Introduction
01:05
UseCase explanation
01:46
Implementation running on Main Thread
06:27
Coroutine Context
04:54
Coroutine Dispatchers
06: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

Structured Concurrency and Coroutine Scopes

15 lectures
Section Introduction
01:41
The unhappy path
03:00
Structured Concurrency
08:26
Coroutine Scopes
05: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

Coroutines Cancellation

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

Coroutines Exception Handling

14 lectures
Section Introduction
02:14
Exception Handling with try-catch
08:41
Coroutine Exception Handler
05:30
Try-Catch VS Coroutine Exception Handler
05:48
launch{} VS async{}
07:28
Exception Handling specifics of coroutineScope{}
03:35
Exception Handling specifics of supervisorScope{}
09:32
Implementation of UseCase13 with try-catch
04:30
Implementation of UseCase13 with CoroutineExceptionHandler
02:51
Implementation of UseCase13 - show results even if a child coroutine fails
11:53
Rethrowing CancellationExceptions
02:19
Coroutines Exception Handling Cheat Sheet
00:04
Conference Talk: Exception Handling in Kotlin Coroutines
00:09
Section Recap
03:42

Testing Coroutines

14 lectures
Section Introduction
02:47
Important Information regarding the new kotlinx-coroutines-test 1.6 APIs
01:20
General Unit Testing Approach
03:02
Using the TestCoroutineDispatcher for our first unit test
18:54
Testing the unhappy path
03:35
Creating a JUnit4 Rule for Testing Coroutine-based code
07:06
Excercise 5: Create a Unit Test for UseCase2
01:22
Solution: Exercise 5
04:43
runBlockingTest{} and VirtualTime
15:23
Testing sequential and concurrent execution
11:30
Testing Timeouts (UseCase5) and Retries (UseCase 6)
00:50
Testing implementations that use Dispatchers.Default or Dispatchers.IO
04:19
TestCoroutineScope and Controlling Coroutine Execution
08:25
Section Recap
02:21

Basics of Kotlin Flow

17 lectures
Section Introduction
02:04
What is a Flow?
14:38
Reactive Programming
03:43
Starting our first Flow Use Case
09:45
Basic Flow Builders
12:38
Exposing a Flow in our DataSource
07:14
Displaying the stock list on the screen
02:54
Basic Terminal operators
17:17
Terminal operator "launchIn()"
09:05
Using "launchIn()" in UseCase1
02:15
Lifecycle Operators
14:45
Terminal operator "asLiveData()"
23:52
Basic Intermediate Operators
18:14
Exercise: Intermediate Operators
04:40
Exercise Solution
16:06
Section Recap
05:43
Slides of the Section
00:02

Flow Exception Handling and Cancellation

7 lectures
Flow Exception Handling
19:46
Exception Transparency
10:28
The "retry()" Operator
10:33
Exercise: Flow Exception Handling
05:01
Exercise Solution
05:54
Flow Cancellation
21:38
Slides of the Section
00:02

StateFlow and SharedFlow

13 lectures
Exposing Flows instead of LiveData in the ViewModel
05:45
Naive Approach - Exposing regular Flows
08:35
Lifecycle-aware Coroutines with "repeatOnLifecycle()"
12:44
Flows are cold
06:22
SharedFlows are hot
09:44
Converting Flows to SharedFlows with "shareIn()"
12:56
Keeping the upstream Flow alive during configuration changes
08:10
The "replay" parameter
05:48
StateFlow
09:26
Converting Flows to StateFlows with "stateIn()"
03:06
SharedFlow VS StateFlow
04:44
Section Recap
06:10
Slides of the Section
00:02

Channels

3 lectures
Channels for Android Development
10:38
Single UI Events
00:15
Slides of the Section
00:02

Concurrent Flows

7 lectures
Important Information
00:08
The buffer() operator
11:00
Dealing with Backpressure (aka BufferOverflow)
13:22
collectLatest(), mapLatest() and transformLatest()
06:22
The conflate() operator
03:03
Buffers in SharedFlows and StateFlows
11:09
Slides of the Section
00:02

Thank you and Bonus

1 lectures
Thank you and Bonus
01:31

Đánh giá của học viên

Chưa có đánh giá
Course Rating
5
0%
4
0%
3
0%
2
0%
1
0%

Bình luận khách hàng

Viết Bình Luận

Bạn đánh giá khoá học này thế nào?

image

Đăng ký get khoá học Udemy - Unica - Gitiho giá chỉ 50k!

Get khoá học giá rẻ ngay trước khi bị fix.