Understand Kotlin Coroutines on Android (Google I/O'19)

46


Coroutines are a feature of Kotlin that help convert callback-based code into sequential code, making code easier to read, write, and understand. This session will show you how to use coroutines on Android, and how the new androidx-concurrent library makes it easy to use them to get things off the main thread. You’ll also learn how the new library helps coroutines work with Architecture Components. This session also covers coroutine patterns, best practices, and even how to test coroutines!

Watch more #io19 here:
Android & Play at Google I/O 2019 Playlist →
Google I/O 2019 All Sessions Playlist →
Learn more on the I/O Website →

Subscribe to the Android Developers Channel →
Get started at →

Speaker(s): Yigit Boyar, Sean McQuillan, Sergey Vasilinetc

TF7514


Source: https://hugochamber.org
Read more all post Android Technology : https://hugochamber.org/android/
46 Comments
  1. Александр Инженер says

    Sergey Strelcov lol

  2. Akaah Dev says

    suspend fun sound like a police inspector suspended 🙂

  3. yasoda nagulla says

    how to communication corotines to UI in jetpack composables? because we can update UI only in composables

  4. Saurabh Prakash says

    Few years from now they will come up with new way for async programming and say coroutines sucks.

  5. Sasi Kumar says

    Its interesting and usefully..Thanks

  6. Dexter Aparicio says

    I wonder how different is the problem domain, that they abandon any iota of similarity and feel of the usual POSIX synchronization primitives. I can see that the new lambda construct has a big role in this, but the whole thing is constructed in not-invented-here fashion

  7. P Square says

    How do you guys test this much complicated scenarios?

  8. Darko Martinović says

    Anybody else thought that that timer is sloppy programming? @20:36

  9. Jesus Angulo says

    Kotlin discover async/await from C# #justKidding xD

  10. Nguyen Xuan Lanh says

    thanks

  11. Sina Rahimi says

    It would be great if they put the slides in somewhere

  12. L. Kärkkäinen says

    These brand-spanking new coroutine concepts are explained in their inventor's blog https://vorpus.org/blog/timeouts-and-cancellation-for-humans/ Kudos to Kotlin team for adopting scopes, cancellation and testing concepts of Trio in such a comprehensive manner!

  13. Дмитрий Толстов says

    why there is viewModelScope and no repositoryScope, or applicationScope. A lot of work done in reposiory calling db and network, I don't need viewModelScope because I return already-made livedata from repo. Also, there are a lot of work I would like to do during my app is running and ok with cancelling it when it's gone. I don't get it.. And there is still NewtorkBoundResource in App Arch Guide on android dev website… it's not thaht coroutiny.

  14. Ankit Gusai says

    The goal is basically set at 4:26 but at the end of the video it feels like(as always) we are back to square one.On the hindsight making anything comprehensive and simple with fragment + activity with their lifecycles is incredibly complex. Throw in a service(Which connects asynchronously and has its own foreground limitations) that needs to be connected and you have to throw everything out of the window.

  15. Matthieu Lucas says

    Best explanation of coroutines i've seen!

  16. hitec16 says

    so many methods and so many scopes. It feels like patch work rather than a complete solution to handling thread calls and orientation changes. Specially in case of fragment. I am sure in future a lot more stuff will come to fix what is done right now. IMHO fragments itself should be re-written. For a beginner this is a very steep learning curve.

  17. 70ME3E says

    10:23 : transforming to another representation from stack to whatever is used for supsendables and then back when resuming, and copying stuff sounds a bit comp intensive, I don't see why we couldn't build separate substacks for the suspendables in the main stack and switching into them and back when necessary. no copying and transforming involved. or am I dumb and threads couldn't manage that and point to other substacks like that temporarily?

  18. SKtheGEEK says

    so tell me how does this work with MVVM which has a repo, viewmodel and view !!!!

  19. Kroken Stiv says

    do you seriously think that coroutines are easier than mvp with rx? I was expecting something really easy but got frustrated.

  20. Ar Na says

    Sorry but worst talk ever. I could not be anymore confused.

  21. Weedy Beats says

    Coroutines are horrible. They are complicated. They don't throw an readable and understandable error to the console when something goes wrong (and something WILL go wrong). They don't allow UI changes.

  22. M Dapp says

    Looking at the actual code of the LifecycleCoroutineScope, I don't think it works the way they claim. Specifically, I don't see any code that would cause coroutines started with 'launchWhenStarted' to suspend when the state is < STARTED. The only thing LifecycleCoroutineScope seems to actually do is cancel when the lifecycle owner is DESTROYED. I'm wondering how much of this talk is actually useable…

  23. Maarttttt says

    Sorry but who are these developers you guys are supposedly talking to? How many completely different async solutions are there now for Android? Like 30? Do all these developers constantly want to learn new ways to perform async tasks?

  24. Manthra Solutions says

    Yes

  25. DiegoTube85 says

    I don't get how Coroutines are presented as an "easy" solution.. They are very hard instead to use properly. I'm trying get it but it's far from easy.. Am I the only one?

  26. Liran Barsisa says

    About 30:00 , I don't understand how this works.It runs this peace of code on the UI thread, on start, right?So how come it waits for "note" variable to be fetched?Does it also re-load the data this way, each time it gets changed, or does it load it just once?

  27. Jeffrey Liu says

    why 1_000 instead of 1000?

  28. Kane says

    Can’t wait to use these coroutine components.

  29. famke theron says

    Kotlin documentation for coroutines sucks (to say the least)!

  30. Mussa Ibragimov says

    I love coroutines. They certainly look better and easier than RxJava. However, I have some concerns. So in order to use coroutines solution, I would need to make changes to all the layers of my codebase?1) Adding "suspend" to my cache and remote functions in model layer.2) Substituting presenters(whatever one has) with viewmodels.3) Make changes to Android(UI) layer.Doesn't look very clean. I don't advocate for Clean Architecture and I'm okay to make changes to presenter and ui layers. I'm just not convinced about model layer.It looks like big teams(if for whatever reason have concurrency problems.. may be they hate rx) that have good separated modules will struggle integrating this solution.Since concurrency is imposed by Android(UI) layer, why can't we solve the problem there? Permeating the solution from top to bottom doesn't smell good.PS. I'll definitely try this solution for my next project. Thank you guys.

  31. XeaLStorm says

    "suspend fun" sounds so sad… 🙁

  32. MrSTJEREM says

    Terrible audio quality 19:00

  33. Farzad Tabashir says

    Thanks guys. Very helpful. Have you shared the lecture notes?

  34. Hán Trung Kiên says

    I have used viewModelScope since it released but now after upgrade dependence version of lifecycle to 2.2.0-alpha01, I can't see lifecycleScope or liveData block??? Please help me to try it.

  35. Khaled Kimboo says

    Just "exactly" like async/await from c# but let's just rename it.

  36. Your Mommy says

    Thank you for shedding light on coroutines. RxJava is powerful tool, but in a lot of cases you can build app using coroutines. I like the fact that open source community supports coroutines a lot as well as Google.

  37. Andrew Orobator says

    Are there any use cases where LifecycleScope should be used over ViewModelScope? It seems like we'd always want to use ViewModelScope to avoid the short deaths during Activity recreation.

  38. soundiscomforting says

    With more focus on Rx in general, Google should show why a reactive paradigm is the way to go. RxJava is a solution for this, coroutines with Flow will also provide a way to achieve it. But this is my issue with comparing RxJava and Coroutines currently. They are not comparable.

  39. SnoopyDoo says

    Boring. Put me to sleep.

  40. Phạm Giang says

    Which dependency(ies) should I use to get LifecycleOwner.lifecycleScope extension? https://developer.android.com/topic/libraries/architecture/coroutines#lifecyclescopeThe document doesn't seem to point that out 😀

  41. HJ Chin says

    Things are like getting out of hand soon. It is more and more costly to understand and master Android app development. Even the Android software engineer at Google has hard time to explain the things in easy to understand way.

  42. Juker says

    Wow! This session was just… perfect! Crazy how much easier and clearer this is compared to the workarounds devs had to do before, really shows how much we can improve tech even now. Really well explained and complete. Would be great if videos like these showing how to use a new feature from the ground up and relating it to other modern libraries were more common. Good work <3

  43. DeLL116 says

    It's crazy how much has changed in Android development in less than 4 years. It's like I learn something, and by the time I've mastered it something new is made to replace what I've just mastered. 🤯

  44. Eric Martori Lopez says

    At around 28:56 should this do the job also:suspend fun loadNote(): Note = viewModelScope.async { repository.loadNote() }I don't see the point on this CompletableDeferred. If it should be loaded only once you could use the lazy delegate.Why is CompletableDeffered needed?

  45. Eric Martori Lopez says

    At around 28:56 should this do the job also:suspend fun loadNote(): Note = viewModelScope.async { repository.loadNote() }I don't see the point on this CompletableDeferred. If it should be loaded only once you could use the lazy delegate.Why is CompletableDeffered needed?

  46. Tomasz Rykała says

    Computatations @ 3:39

Leave A Reply

Your email address will not be published.