axehit
10/15/2021, 10:04 AMDisposableEffect
.
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.Albert Chang
10/15/2021, 10:58 AMonDispose
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.axehit
10/15/2021, 11:23 AMAlbert Chang
10/15/2021, 11:25 AMLocalLifecycleOwner.current
in a DisposableEffect
.axehit
10/15/2021, 11:35 AMIan Lake
10/15/2021, 6:54 PMDisposableEffect
docs actually show how to use that API for listening for lifecycle events: https://developer.android.com/jetpack/compose/side-effects#disposableeffect