jetpack 撰写 navController popBackStack 多个页面

gao*_*way 8 android-jetpack-compose

我有 A、B 和 C 三个页面,通过导航顺序访问这三个页面。

\n

A -> B -> C

\n

如何从C返回A?

\n

这些官方描述应该有用,但是don\xe2\x80\x99不懂。

\n
// Pop everything up to the "home" destination off the back stack before\n// navigating to the "friends" destination\nnavController.navigate(\xe2\x80\x9cfriends\xe2\x80\x9d) {\n    popUpTo("home")\n}\n\n// Pop everything up to and including the "home" destination off\n// the back stack before navigating to the "friends" destination\nnavController.navigate("friends") {\n    popUpTo("home") { inclusive = true }\n}\n\n// Navigate to the "search\xe2\x80\x9d destination only if we\xe2\x80\x99re not already on\n// the "search" destination, avoiding multiple copies on the top of the\n// back stack\nnavController.navigate("search") {\n    launchSingleTop = true\n}\n
Run Code Online (Sandbox Code Playgroud)\n

Phi*_*hov 15

您所指的导航显示了导航到特定目的地时如何清除堆栈。

如果需要清除导航堆栈,可以使用popBackStack,如下所示:

navController.popBackStack(route = "A", inclusive = false)
Run Code Online (Sandbox Code Playgroud)

  • 如果我想使用带参数的“popBackStack”怎么办? (2认同)