January 2018
Intermediate to advanced
434 pages
14h 1m
English
Let's follow the given steps to understand how coroutines work in Kotlin:
class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) launch { delay(10000) println("Hello") } }}
The preceding function will print "Hello" in the Android Studio console after a duration of 10 seconds. Note that we have used the launch function to start a coroutine, which returns a Job, but it does not carry any resulting value. It starts a new coroutine on a given thread pool (by default, coroutines are run on a shared ...
Read now
Unlock full access