I currently have a flat compose navigation hierarchy, and when navigating from the 'home' screen to another screen, any hot flows tied to the viewModelScope of the 'home' screen will continue to operate as expected. I want the viewModel to stay alive, but I want the flows paused while not inside that composable, so I load/dispose them inside the 'home' composable via a DisposableEffect with job cancellation. Is there a more sensible way to handle this?
i
Ian Lake
06/09/2021, 5:00 AM
There's a lot to unpack here. A hot flow is, by definition, always going, so there's no such thing as 'pausing' it. If you're using something like
shareIn()
or
stateIn
, then it sounds like you should be using
SharingStated.WhileSubscribed()
, which would automatically stop the upstream collecting when your