kluck
05/03/2019, 7:09 AMDispatchers.Main
on Android. Here are my dependencies:
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.2.1")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.2.1")
And on my activity, a simple launch would do nothing when ran on Dispatchers.Main
, whereas it works on `Dispatchers.IO`:
GlobalScope.launch(Dispatchers.Main) { // Works with <http://Dispatchers.IO|Dispatchers.IO>
Timber.d("Current thread: ${Thread.currentThread().name}")
}
In debug, I can access Dispatchers.Main
which is correctly plugged to the android handler.
Any idea what I'm doing wrong?tseisel
05/03/2019, 11:23 AMDispatchers.Main
on Android.
I'd advocate against using GlobalScope
, as it doesn't account for structured concurrency. Try to launch your coroutine from the scope of an `Activity`/`Fragment`/`ViewModel`