Hello guys, I have a question regarding `Disposabl...
# compose
a
Hello guys, I have a question regarding
DisposableEffect
. While using this effect I observed that if I move to another activity, then the
onDispose
lambda in the
DisposableEffect
of the composable in previous activity I navigated from didn’t get called. Is this an expected behaviour? That since I didn’t use compose navigation instead activity navigation
onDispose
isn’t called. And on the same topic can you suggest some other alternative of disposing data when composable moves out of view in case of activity navigation, my usecase is I want to send a tracking event everytime user moves out of screen.
a
onDispose
is similar to activity's
onDestroy
. Unlike fragments and composables, when you move to a new activity, the previous activity isn't destoryed. It just stops.
👍 2
a
Ok, got it, then is there some way in composable to know that it has move to background or onPause state analogous API?
a
You can observe the lifecycle of
LocalLifecycleOwner.current
in a
DisposableEffect
.
a
Thanks, I’ll try that out.
i
The
DisposableEffect
docs actually show how to use that API for listening for lifecycle events: https://developer.android.com/jetpack/compose/side-effects#disposableeffect
👍 2