In my app I need to get some values from an API. C...
# android
z
In my app I need to get some values from an API. Currently I'm just doing the API call inside my the init block of a class that I'm injecting using Koin. I'm doing the API call in a runBlocking call from kotlin coroutines but that does block the UI from loading until the variables are set. What would be the proper way of doing this so that it isn't blocking the UI and properly indicates to the user that it's loading?
😶 1
c
Please Nicolas, check the channel description for proper other resources where to ask your general android questions.
g
Never use runBlocking in UI related code, not really clear why you need it if you already has a coroutine as you said. First I would recommend checking this guide: https://github.com/Kotlin/kotlinx.coroutines/blob/master/ui/coroutines-guide-ui.md
z
This is in my viewmodel. It gets called on the main thread which in turn blocks UI. Problem is if I dont block UI then it loads before the actual variables are initialized and then results in errors
g
You shouldn't rely on initialization order. Hard to recommend something specific without some self-contained example