# compose

Stylianos Gakis

03/03/2023, 3:17 PM
Got a situation where I got this setup:
(which opens ChildActivity) ->
(which contains a NavHost that I will mention here). And I got some trouble with navigateUp(). More in 🧵
Inside this navHost, I got this structure:
Copy code
NavHost(startDestination = "A") {
    route = "A",
    startDestination = "First",
  ) {
    composable(route = "First") {
        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,
doesn’t succeed, onSupportNavigateUp() also doesn’t succeed and it falls back to finish(). When I call onBack() from inside
, this works fine, and the activity is finished. When I then trigger the
navController.navigate("Second") { popUpTo("A") }
, and from inside
I call
, 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
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 up
In this case I guess one thing I may be messing up is what I should decide to do with my
. 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.
I guess what I was facing actually had to do with what
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 🤷‍♂️