Hey guys, one question, is is possible to collect ...
# android
f
Hey guys, one question, is is possible to collect the data/values of a
MutableStateFlow
in 2 fragments of a viewpager?
m
you could do so, if you are using the same viewmodel / presenter and inside it the mutablestateflow
f
I am. 2 fragments are using the same viewmodel that holds the mutablestateflow and then both fragment do the collect inside:
Copy code
viewLifecycleOwner.lifecycleScope.launch {
    repeatOnLifecycle(Lifecycle.State.STARTED) {
        viewModel.myStateFlow.collect {
but only the first fragment (first tab of the viewpager) receives the
_myStateFlow.value = Status.Success(data)
a
Where you are making your viewmodel instance, can you show that line??
Okay right you have written repeatonlifecycle in onstarted state, in viewpager there is a offset option which is 1 by default so adjacent fragment , onstart will not be called that's why it is not collecting, don't use that just collect or use onresume instead