January 2018
Intermediate to advanced
434 pages
14h 1m
English
Whenever in doubt, whether using thread or coroutines, remember these lines by Roman (an engineer from the JetBrains team):
In Android's context, you always want to update the UI, but you can't do it from background thread. Coroutines have a solution for this. Let's take a look at the next example:
launch(UI) { val sum = lengthyJobOne.await() +lengthyJobTwo.await() myTextView.text = "Sum of results is $sum."}
In the preceding code, not only can we compute two jobs in the background without blocking the main thread, we can also touch the UI thread for updating views.
Read now
Unlock full access