When you use launch
or async
without any arguments, it actually uses DefaultDispatcher.
DefaultDispatcher: It is currently equal to CommonPool, but the value is subject to change in the future.
For background tasks, use CommonPool
or leave it blank.
For UI tasks (e.g. involve update for view), use UI
from kotlinx-coroutines-android.
Edit build.gradle
(Module).
dependencies {
// https://github.com/Kotlin/kotlinx.coroutines/releases
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:0.23.4'
}