最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

android - Multiple back stacks without clearing parent back stack (Jetpack Compose) - Stack Overflow

programmeradmin0浏览0评论

My project has a bottom bar with tabs A, B and C. Tab C view has its own navigation C1, C2, C3. Now if the user navigates e.g. C -> C1 -> C2, than goes to tab B, than back to tab C again, I want him to immediately land on tab C2 (from which he left C tab). And here the multiple back stacks technique provided by Android documentation works well:

navController.navigate(selectedBottomNavRoute) {
  launchSingleTop = true
  restoreState = true
  popUpTo(navController.graph.findStartDestination().id) {
    saveState = true
  }
}

The key is saveState = true which "saves" and recreates the state of the child navigation controller used for C1-C2-C3 navigation.

But the problem is that when I use popUpTo I lose the back stake of navController. And without popUpTo I can't use saveState functionality.

Using this technique, if the user simply navigates A -> B -> C, presses the "Back" button, he appears in A! But obviously he expects to appear in B.

Is it possible to implement multiple back stacks without losing the back stack of the "parent" navigation controller?

After all, why did Android devs implement the saveState function inside PopUpToBuilder and not, for example, in NavOptionsBuilder? :)

发布评论

评论列表(0)

  1. 暂无评论