Hi everyone, just would like to ask which one is b...
# android
i
Hi everyone, just would like to ask which one is better to use when inside a Coroutine Context in a background Pool to run an operation on the UI Thead: Handler(Looper.getMainLooper()).post{ /* running on UI here */ } or launch(UI) { /* running on UI here */ } I'm maintaining a library with a lot of calls to the UI and don't know which to choose
g
Sure, use coroutine dispatcher
But UI is deprecated, use Dispatchers.Main Also, probably you don't need
launch
, just
withContext
, but it depends on your case
i
I see, thx, i'll start to use it 🙂
Is it safe to swap all my Handler post usages to Main dispatcher? I'm wanting to use it as a standard
g
Should be safe, I don’t see any potential issues. But if you have some problems with it just report an issue
i
Ok, thx, I started to use only coroutines dispatchers everywhere and they are doing really well, coroutines are really awesome.
g
@Icaro Temponi Just in case, if didn’t read “Coroutines Guide to UI programming” yet, I highly recommend to do that: https://github.com/Kotlin/kotlinx.coroutines/blob/master/ui/coroutines-guide-ui.md