jean
01/07/2021, 8:31 AMlifecycleScope.launch {
viewModel.state.collect { updateState(it, binding) }
}
lifecycleScope.launch {
viewModel.load()
}
I cannot have viewModel.load()
inside the first block after collect
since it never ends and if I put it before I miss a bunch of events. Is there a way to write this in a better way?Giorgos Neokleous
01/07/2021, 9:38 AMlaunchIn
?
lifecycleScope.launch {
viewModel.state.onEach { updateState(it, binding) }.launchIn(lifecycleScope)
viewModel.load()
}
Giorgos Neokleous
01/07/2021, 9:39 AMjean
01/07/2021, 10:01 AM