https://kotlinlang.org logo
#coroutines
Title
# coroutines
s

Slava Glushenkov

12/05/2018, 4:36 PM
Why this code updates UI inside IO context and don't crash android app as expected?
Copy code
GlobalScope.launch(<http://Dispatchers.IO|Dispatchers.IO>) {
 textView.text = "New Text"
}
g

gildor

12/05/2018, 5:05 PM
Maybe you override error handler. Actually I'm not 100% sure that setText actually has assert for UI thread, I believe some methods of view just silently fail without exception
l

littlelightcz

12/08/2018, 12:42 PM
I've also seen similar behaviour that first UI update on non-UI running coroutine passed, but further calls later on the same coroutine threw an Exception as expected. I was thinking that maybe coroutine starts so fast that in the beginning these asserts somehow don't notice the thread switch 😁
g

gildor

12/08/2018, 1:12 PM
I think it's just related to how textview checks for main thread, not to coroutines itself
4 Views