为什么底部导航状态不保存在撰写中?

Mak*_*mka 2 navigation android kotlin android-jetpack-compose

我使用一张图表,其中登录屏幕被设置为开始屏幕。从登录屏幕,您可以导航到特定选项卡底部导航。如果从登录屏幕转到底部导航屏幕时使用 popUpTo(0) 清除堆栈,则在选项卡之间切换时底部导航将停止保存状态。

在选项卡之间导航:

navController.navigate(item.route) {
    navController.graph.startDestinationRoute?.let { route ->
        popUpTo(route) {
            saveState = true
        }
    }
    launchSingleTop = true
    restoreState = true
}
Run Code Online (Sandbox Code Playgroud)

从登录导航到底部选项卡

navController.navigate(route = NavigationItem.Home.route, builder = { popUpTo(0) })
Run Code Online (Sandbox Code Playgroud)

sno*_*lax 5

因为没有剩余的堆栈可以保存。

navController.navigate(screen.route) {
              // Pop up to the start destination of the graph to
              // avoid building up a large stack of destinations
              // on the back stack as users select items
              popUpTo(navController.graph.findStartDestination().id) {
                saveState = true
              }
              // Avoid multiple copies of the same destination when
              // reselecting the same item
              launchSingleTop = true
              // Restore state when reselecting a previously selected item
              restoreState = true
            }
Run Code Online (Sandbox Code Playgroud)