onCreate.kt
# android
d
onCreate.kt
w
Isn’t it because you’re just blocking the entire UI thread until your call returns?
runBlocking
will wait until the block completes fully
So the progress won’t show, because the UI thread is blocked
d
Aight, that could make sense. I'm new to coroutines, so maybe I took bad approach. I thought getStudents() will get executed on a "separate thread".
@wasyl how could I not block the UI thread/rendering and still wait until getStudents() returns a result? Any suggestion what should I look into?
but anyways, it's confusing as showLoadingAnimation() is called before I'm calling runBlocking { getStudents() }
w
That’s how Android works. You’re calling
showLoadingAnimation
on the main thread, and this doesn’t immediately show progress, but enqueues an action to show it as soon as them main thread is available. But since you immediately call
runBlocking
on the main thread, the system doesn’t have an opportunity to show the progress.
Anyway you should look into coroutine scopes and run your action within some scope. I know there’s a convenient
viewModelScope
if you’re using `ViewModel`s