I have the following code in my Activity which i call in onCreate
val carFlow: Flow<Car> = carFlowProvider.provideFlow()
viewModel.testingLiveData.observe(this, Observer { testValue ->
lifecycleScope.launch {
refreshCar(carFlow.firstOrNull(), testValue)
}
}
})
This works fine on first activity launch and refreshCar()
method is called with available value of Car
from carFlow
.
But after screen rotation, when ViewModel posts a new testValue
into testingLiveData
, the launch block is called but carFlow.FirstOrNull()
doesn’t execute and so refreshCar()
method is never called.
This happens only after screen rotation.
Thanks
Tried using repeatOnLifecycle(STARTED)
but that didn’t work either