Android Coroutines: How to manage async tasks in Kotlin

Google+ Pinterest LinkedIn Tumblr +

Video is ready, Click Here to View ×

Take a good look at the current state of coroutines support in Android libraries and tools, explore some interesting and not-so-obvious edge cases when dealing with Kotlin code that includes coroutines and interop with Java, and briefly look at some new developments in Kotlin coroutines, namely StateFlow and its comparison with LiveData, and SharedFlow.

Coroutines blog posts →
Coroutines 101 codelab →
Other coroutines codelabs →
Check out the 11 Weeks of Android website →

Related Playlists:
Languages – 11 Weeks of Android playlist →
11 Weeks of Android playlist →

Subscribe to Android Developers →

Manuel Vicente Vivo

#featured #android11 #11WeeksOfAndroid


About Author


  1. How do you cancel a job via kotlin coroutines, in the same way you can do for AsyncTask?
    For when you have AsyncTask instance, you have a choice, of canceling with and without interruption.
    ON kotlin coroutines, I can see that you have to choose it when you create it. Is it correct?

  2. I used to write Android apps on Java but two years ago I switched to Flutter on Dart.

    And never regretted since then. Everything is so much easier in Flutter.

    I remember how AsyncTasks first appeared and became recommended, now its deprecated… I'm tired of it frankly speaking.

    Why should I learn Kotlin? Why should have created new programming language just for Android?
    Kotlin is not used anywhere else

  3. Snippet at 4:11 has an error:

    is actually equivalent of
    thus readFromDb() will be ran on the thread createWork is called(main?).
    And it's not about RxJava, it's about Kotlin(or Java): to call a function(Single.just) we have to calculate its parameters first.

  4. Is it just me or in the first example the:
    val dbData = readFromDb()
    should've been "data"?
    Looks like you are "uploading" to the remote server, the variable is called "data" and it isn't declared in the fun's scope?

  5. So what is the rule for collecting flows in UI controllers? asLiveData().observe(..) when I want to observe hot streams as cold flows and lifecycleScope.launchWhenStarted when I observe e.g. database?