maxmello
09/15/2021, 2:52 PMoverride fun onCreate(…) {
…
scope.launch /* on Dispatchers.Main */ {
viewModel.flow.collect { it ->
uiElement.text = it
}
}
}
Is is better to do launch(Dispatchers.Default)
and then wrap the UI operation in withContext(Dispatchers.Main)
, or is there no practical difference since the collect is suspending and not blocking? If I would do more operations except setting the UI element, I would always do the approach with launch on Dispatchers.Default + withContext(Main), but here I really only update the UI on collectade
09/15/2021, 3:09 PMmaxmello
09/15/2021, 3:13 PMade
09/15/2021, 3:18 PMmaxmello
09/15/2021, 3:19 PM