Status Update
Comments
jb...@google.com <jb...@google.com>
ap...@google.com <ap...@google.com> #2
Could you please provide a minimal sample that reproduces this issue?
ap...@google.com <ap...@google.com> #3
Yes, of course
@Composable
private fun DemoNavHost() {
val controller = rememberNavController()
NavHost(
navController = controller,
startDestination = "mainRoute",
modifier = Modifier.fillMaxSize()
) {
composable("mainRoute") {
Surface() {
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
Button(
onClick = {
controller.navigate("demoDialog")
controller.navigate("demoDialog") // Simulate a quick click by the user
}
) {
Text(text = "show dialog")
}
}
}
}
dialog("demoDialog") {
val context = LocalContext.current
val lifecycle = LocalLifecycleOwner.current
Surface() {
Column() {
Text(text = "I'm demo dialog")
Button(
onClick = {
Toast
.makeText(
context,
"${lifecycle.lifecycle.currentState}",
Toast.LENGTH_SHORT
)
.show()
}
) {
Text(text = "check lifecycle")
}
Button(onClick = controller::popBackStack) {
Text(text = "close")
}
}
}
}
}
}
Steps:
Step 1: Click the show dialog
button on mainRoute
Step 2: Because 2 pop-up windows pop up, we close the top one
Step 3: Click the check lifecycle
button on the pop-up window, you can see STARTED
instead of RESUMED
I have also checked the cause, which is consistent with the description in my question.
jb...@google.com <jb...@google.com> #4
In fact, I found another problem. When the tester frequently clicks the button, the button event is to display a Dialog
, Dialog
is set to be destroyed by external click, so Dialog
is always displayed and destroyed
Interesting thing, because it may be too fast, causing DialogHost
to not notice that Dialog
appears and disappears, but it has actually joined NavController#_visibleEntries
But because NavHost#DialogHost
did not process DisposableEffect
, it will not execute dialogNavigator#onTransitionComplete
, so it will not be removed from NavController#_visibleEntries
, and a NavBackStackEntry
leak occurs
The reason may be that the pop-up window appears and disappears within one frame
jb...@google.com <jb...@google.com> #5
Hi, can you please file a separate bug for the issue you see in
On initial bug - when multiple dialogs are open at the same time and the top one is dismissed, the second dialog in backstack is marked as transitioning to hold it in STARTED state until the top dialog has completed transitioning. But the second dialog was not marked as complete when composed so it stays in STARTED state instead of moving to expected RESUMED state.
an...@google.com <an...@google.com> #6
Thank you for your answer, I will open a separate post to ask a separate question;
st...@sieveo.com <st...@sieveo.com> #7
Thanks for filing the new bug! I was thinking a separate bug for the issue you see in commment#4 with NavBackStackEntry
possibly leaking. I'm gonna update the new bug's description to match that.
jb...@google.com <jb...@google.com> #8
Fixed internally and will be available in navigation 2.7.2
.
Description
Version used: 2.2.0-r01
Devices/Android versions reproduced on: Android 9.0.0
If NavHostFragment is declared in FragmentContainerView it won't set its NavController's graph when it is recreated from configuration change. I believe the reason for this is that FragmentContainerView, unlike <fragment> tag, doesn't call fragment's onInflate() when it was recreated by FragmentManager, and NavHostFragment sets its mGraphId variable only in onInflate(). So when NavHostFragment is recreated its graph is lost.