i have some code like:
doAsync{
...
uiThread{
...
}
}
how can i replace doAsync and uiThread with something new from kotlinx-coroutines-core lib?
Go to Tools → Kotlin → Configure Kotlin Plugin Updates, select “Stable” in the Update channel drop-down list, and then click Check for updates. We are adding coroutines-core along with coroutines-android. Now, sync your project with gradle files and you are ready use the latest Coroutines.
A coroutine is a concurrency design pattern that you can use on Android to simplify code that executes asynchronously. Coroutines were added to Kotlin in version 1.3 and are based on established concepts from other languages.
The Anko library is an Android library written and maintained by JetBrains. Anko helps you to work faster and smarter when building Android apps. From what I've gathered, the above graphic is how the name Anko came about. Anko has four parts: Anko Commons.
coroutines library version 1.3.7:
GlobalScope.async(Dispatchers.Default) {
// do background work
withContext(Main) {
// do ui work
}
}
The exact replacement for the pseudocode in the question is
GlobalScope.launch(Dispatchers.Default) { // replaces doAsync
...
launch(Dispatchers.Main) { // replaces uiThread
...
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With