Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jetpack compose navController popBackStack Multiple pages

I have three pages A, B and C, which are accessed sequentially through navigation.

A -> B -> C

How can I return from C to A?

These official descriptions should be useful, but don’t understand.

// Pop everything up to the "home" destination off the back stack before
// navigating to the "friends" destination
navController.navigate(“friends”) {
    popUpTo("home")
}

// Pop everything up to and including the "home" destination off
// the back stack before navigating to the "friends" destination
navController.navigate("friends") {
    popUpTo("home") { inclusive = true }
}

// Navigate to the "search” destination only if we’re not already on
// the "search" destination, avoiding multiple copies on the top of the
// back stack
navController.navigate("search") {
    launchSingleTop = true
}
like image 962
gaohomway Avatar asked May 13 '26 12:05

gaohomway


1 Answers

The navigation you are referring to shows how to clear the stack when navigating to a specific destination.

If you need to clear the navigation stack, you can use popBackStack as shown below:

navController.popBackStack(route = "A", inclusive = false)
like image 85
Philip Dukhov Avatar answered May 18 '26 20:05

Philip Dukhov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!