Hi, im trying to learn coroutines/Flow I want to ...
# coroutines
u
Hi, im trying to learn coroutines/Flow I want to subscribe my
viewModel.state
flow in android Activity, between onStart and onStop I do that, and notice that after having activity.onStop called, next activity.onStart doesn't start listening to the flow So I conclude scopes are not reusable But this is android reality and I need that. I need equivalent of rx
compositeDisposable.clear()
Is the only solution to have abstraction over the scope which will create new scope instances?
i
Sounds like you should be using
lifecycleScope.launchWhenStarted
As that stops collect callbacks when you get stopped and resumes callbacks when you get started again: https://developer.android.com/topic/libraries/architecture/coroutines#suspend
u
sure, but I'd like to know the underlying issue, so solving it without lifecycleScope
i
Cancel means permanently cancelled, yes. That's why those methods are there to handle this correctly