July 2018
Intermediate to advanced
400 pages
12h 14m
English
To solve the crash, you need a way to move the network request to a background thread instead of the main thread. Kotlin 1.1 and all versions since include a coroutines API that gives you a way to do so concisely.
As of this writing, coroutines are considered experimental (though they are expected to become a permanent feature of Kotlin), so to use them you must opt in by enabling them. You also need a coroutine library extension to use coroutines with Android. Click the Logcat tab again to hide it, and open your app/build.gradle file. Enable coroutines and add the new dependency there:
Listing 22.6 Enabling coroutines (app/build.gradle)
...
kotlin {
experimental {
coroutines 'enable'
}
} dependencies { ...Read now
Unlock full access