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

标签 android kotlin navigation android-jetpack-compose

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

在选项卡之间导航:

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

从登录导航到底部选项卡

navController.navigate(route = NavigationItem.Home.route, builder = { popUpTo(0) })

最佳答案

因为没有堆栈可供保存。

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
            }

关于android - 为什么底部导航状态不保存在撰写中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73391089/

相关文章:

kotlin - 如何在 Kotlin 中为内部阻塞线程进行挂起调用 "wait"?

javascript - jQuery 动画导航如何在单击时折叠其他元素

jquery - 寻找 jQuery 效果来逐渐显示隐藏的 DIV/图像

php - 是否有更简洁的方法来处理每页的侧边栏事件状态?

android - Apache Legacy 的 Proguard 问题(不使用该库时)

android - 将图像动态加载到对话框中

static - Kotlin 对象 vs 伴生对象 vs 包作用域方法

android - Room 查询是否异步发生?

android - 在不创建文件的情况下将 byte[] 数据发送到 Activity

android - 通知中的 Intent 不起作用