Why lifecycleScope is not waiting for viewmodelscope to finish?
I want a button to execute viewmodel's method before navigating to another fragment, but it seems that it is not waiting for all suspending functions to finish before changing screen:
View.class
nextButton.setOnClickListener {
val action = FragmentDirections.AToB()
lifecycleScope.launch {
getViewModel().doSomething()
findNavController().safeNavigate(action)
}
}
ViewModel.class
suspend fun doSomething() {
viewModelScope.launch {...