adrielcafe / voyager

🛸 A pragmatic navigation library for Jetpack Compose
https://voyager.adriel.cafe
MIT License
2.55k stars 130 forks source link

Lifecycle Events Not Triggered During Screen Navigation #469

Open singla-harshul opened 2 months ago

singla-harshul commented 2 months ago

While navigating from one screen to another, the onPause and onStop lifecycle events of the previous screen are not being called.

akardas16 commented 1 month ago

While navigating from one screen to another, the onPause and onStop lifecycle events of the previous screen are not being called.

yes, I can also repeat it.

skymansandy commented 1 month ago

Facing same issue as well. @adrielcafe @DevNatan Is there any fix for this issue? I'm seeing this was closed as one of the fix PR had got merged: https://github.com/adrielcafe/voyager/issues/42

We are still facing the issue in 1.1.0-beta2

AshuTyagi16 commented 1 month ago

I’m also facing the same issue.

Is there any fix for this ?

skymansandy commented 1 month ago

I'm using this way to listen to lifecycle event.

val lifecycleOwner = LocalLifecycleOwner.current

        DisposableEffect(lifecycleOwner) {
            val observer = LifecycleEventObserver { _, event ->
                // Handle event
            }

            lifecycleOwner.lifecycle.addObserver(observer)
            onDispose {
                lifecycleOwner.lifecycle.removeObserver(observer)
            }
        }

I guess the issue here is with lifecycle observer being removed in onDispose as Screen content is disposed on navigating to new page.

onPause/onStop events are triggered for that screen, but consuming it this way is not possible. What would be the right way in this case?