Android Coroutine Guideline: Introduction



3rd Party Library

  • We need concurrency, this is inherent.
  • We need main-safe methods.
  • We want to write code sequentially just like the above one.


Basic Coroutine Sample




  • Coroutines are light-weight threads. So you can create as many coroutines as you want. You can not do this with threads.
  • Suspend functions are playing a really important role in coroutines. A coroutine can suspend the function and resume code when the function is finished its job.
  • We can switch to any context by using withContext(). (We have Dispatchers.IO, Dispatcher.MAIN, Dispatcher.DEFAULT, Dispatchers.UNCONFINED)
  • We can launch a coroutine with the launch coroutine builder.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store