Isaac
04/12/2022, 8:17 PMviewLifecycleOwner.lifecycleScope.launch {
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED){
Timber.d("I'm in fragment with ${viewModel.progressType.tabId}")
parentViewModel.progressItemListFlow.collect {
Timber.d("I'm in fragment collect with ${viewModel.progressType.tabId}")
if (it[0].progressType.tabId == viewModel.progressType.tabId)
adapter.setup(it)
}
}
}
The problem is that I have this code is for multiple fragments in a viewpager with a shared viewModel. I start at a particular tab(fragment) in the viewpager, and make the api call to get the data I’m emitting in the flow, however the fragment I’m currently on, does not collect the flow. I have to go to a different tab in the viewpager and return before the flow is collected. I have put two log statements, and the first one get’s called, but the second one never gets called the first time. Does anyone know what may be wrong with this?