Stylianos Gakis
03/03/2023, 3:17 PMRootActivity
(which opens ChildActivity) -> ChildActivity
(which contains a NavHost that I will mention here).
And I got some trouble with navigateUp(). More in đź§µStylianos Gakis
03/03/2023, 3:23 PMNavHost(startDestination = "A") {
navigation(
route = "A",
startDestination = "First",
) {
composable(route = "First") {
FirstComposable(
navigateToSecond = { navController.navigate("Second") { popUpTo("A") } },
onBack = { navController.navigateUp() || this@ChildActivity.onSupportNavigateUp() || this@ChildActivity.finish() }
)
}
composable(route = "Second") {
SecondComposable(onBack = { navController.navigateUp() || this@ChildActivity.onSupportNavigateUp() || this@ChildActivity.finish() })
}
}
}
Where I want to go to First, from there move to Second, but remove “First” off the backstack, so that from “Second”, if we’ve not been deep linked into there, when they press on the topAppBar back arrow icon, navController.navigateUp()
doesn’t succeed, onSupportNavigateUp() also doesn’t succeed and it falls back to finish().
When I call onBack() from inside FirstComposable
, this works fine, and the activity is finished. When I then trigger the navController.navigate("Second") { popUpTo("A") }
, and from inside SecondComposable
I call onBack
, it somehow tried to re-instantiate my ChildActivity instead since navController.navigateUp() does succeed somehow, even though I thought I’d have an empty backstack at that point since I popped it all before going to “Second”.
I wonder if there’s something wrong I am doing with my popUpTo
and how I should be doing this properly in case I am in such a nested graph situation. Or if it’s something else I am messing upStylianos Gakis
03/03/2023, 4:25 PMpopUpTo
.
In order to get this “clear backstack, aside from “Second” being in the front” if I should do
• navController.navigate(“Second”) { popUpTo(“A”) }
• navController.navigate(“Second”) { popUpTo(“First”) }
• navController.navigate(“Second”) { popUpTo(“A”) { inclusive = true } }
• navController.navigate(“Second”) { popUpTo(“First”) { inclusive = true } }
• something else
Not sure tbh, and I haven’t found anything in the docs specifying this, only cases where there aren’t nested graphs like this, like here.Stylianos Gakis
03/03/2023, 4:27 PMnavController.navigateUp()
does and how it works differently when called from the startDestination of a navigation graph, vs when called from another route which is not he start destination.
At least that’s what I think I figured out here 🤷‍♂️