我使用一张图表,其中登录屏幕被设置为开始屏幕。从登录屏幕,您可以导航到特定选项卡 底部导航。如果从登录屏幕转到底部导航屏幕时使用 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/