Background notifications

Report a typo

Loading data from the server can be a long operation, so we want to entertain a user while the computer is busy loading the content. To do that let's launch a function that writes a message every second that the app is still alive. When the loading is done our app should finish and so should our loading and notification functions.

Start two coroutines. Start `loadData` in a blocking way so the app doesn't finish before it's done. Start `printProgress` in a fire-and-forget way to keep printing the message in the background while the app is running.

Tip: `launch` coroutine builder requires a scope as the receiver, for example `GlobalScope.launch()`

Write a program in Kotlin
import kotlinx.coroutines.*
import kotlin.system.measureTimeMillis

fun doAllTheJob() {
// put your code here
// use suspending functions
// printProgress() and loadData()
}
___

Create a free account to access the full topic