This is part of the "Android Data and Networking" learning path. View Path

Kotlin Flow: Getting Started

Mar 26 2020 · Video Course (1 hr, 5 mins) · Advanced

Kotlin Flow is a new asynchronous stream library from JetBrains, the company behind the Kotlin language. Sharing many similarities with Rx streams, Kotlin Flow is built on top of Kotlin Coroutines. Get started by learning the concepts and usage patterns for the Flow API within IntelliJ IDEA projects. Then, see Flow in action in an Android app. Note: Flow is experimental in Kotlin 1.3 but will likely be stable in Kotlin 1.4.

4.5/5 8 Ratings

Version

  • Kotlin 1.3, Android 5.0, IntelliJ IDEA 2019.3

Kotlin Flow Primer

Learn about where Kotlin Flow fits in the landscape of asynchronous programming on Android, and define cold, asynchronous streams.

1

See how to create an asynchronous flow and compare to synchronous alternatives, and learn about collecting a flow.

2

Learn about the use of various flow builders, including the flowOf function and asFlow that converts collections like lists to flows.

3

See how Kotlin Flow adheres to the notion of structured concurrency, and implement a simple use case of flow cancellation via a timeout.

4

Learn how to manipulate flows with the common map, filter, and reduce operators and also learn about the Flow transform operator and terminal operators.

5

Unlike Rx streams, completion events are not inherent in flows. See how to add actions that run when a flow completes, both imperatively and declaratively.

6

Working with Flows

Coroutine context determines the configuration in which a flow runs; see how to change the coroutine context using flowOn.

7

Flows are intended to be used for long running operations; see how to use buffering to handle flow processing and flow emission taking different times.

8

Learn about the operators that are available in the Kotlin Flow API to combine flows, and also see how to use the onEach and flatMap operators.

9

Exceptions may occur when flow elements are being emitted or collected; see how to handle exceptions in both cases.

10

Kotlin Flow on Android

Switch from simple flows in IntelliJ IDEA to working with flows in an Android app, and get an introduction to the Android sample project.

11

See how to create a flow running from the app local database through the app repository and ViewModel and into the user interface.

12

Learn about how channels can be used to inject elements into flows, and apply your knowledge of flow operators in the Android app.

13

Apply what you learned about combining operators to combine a flow from the database with a flow of data retrieved over the network.

14

Who is this for?

Experienced Android developers familiar with Kotlin Coroutines who are interested in learning about the new Kotlin Flow approach to reactive stream programming.

This course expects you to be familiar with the Android SDK and Kotlin at an intermediate level. Familiarity with RxJava is helpful but not required.

Covered concepts

  • Working with asynchronous streams.
  • Creating a flow using a flow builder.
  • Collecting flows and flow terminal operators.
  • Taking action on flow completion.
  • Flow cancellation.
  • Flow exception handling.
  • Manipulating flows with operators.
  • Flow context and scope.
  • Buffering flows.
  • Combining flows.
  • Using channels with flows.

Contributors

Comments