https://kotlinlang.org logo
#coroutines
Title
# coroutines
u

ursus

10/18/2020, 4:37 PM
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

Ian Lake

10/18/2020, 5:22 PM
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

ursus

10/18/2020, 6:47 PM
sure, but I'd like to know the underlying issue, so solving it without lifecycleScope
i

Ian Lake

10/18/2020, 7:16 PM
Cancel means permanently cancelled, yes. That's why those methods are there to handle this correctly
2 Views