What is the error I am making here? The coroutine ...
# coroutines
p
What is the error I am making here? The coroutine should run on the main thread as seen by the log output. However I still get the exception that I can’t use a Toast here.
t
I think the logs are misleading here, the coroutineContext does not indicate on which thread you are, unlike
Thread.currentThread()
that clearly indicates that you are running on Dispatcher.Default. if you are not sure you are running on the Main Thread, wrap the Toast code into
withContext(Dispatchers.Main)
.
p
I can’t do that because it is not in a suspending function. The only option I have is runOnUiThread(). Does that work the same way or do I have to be aware of other pitfalls as well?