https://kotlinlang.org logo
#android
Title
# android
i

Icaro Temponi

09/30/2018, 3:49 PM
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

gildor

09/30/2018, 4:10 PM
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

Icaro Temponi

09/30/2018, 4:12 PM
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

gildor

09/30/2018, 11:17 PM
Should be safe, I don’t see any potential issues. But if you have some problems with it just report an issue
i

Icaro Temponi

10/01/2018, 2:57 AM
Ok, thx, I started to use only coroutines dispatchers everywhere and they are doing really well, coroutines are really awesome.
g

gildor

10/01/2018, 3:35 AM
@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
2 Views