[英]Android navigation component back stack
i created a nav graph with fragments fragA->fragB->fragC-fragD->fragE->fragF->fragG.我用片段 fragA->fragB->fragC-fragD->fragE->fragF->fragG 创建了一个导航图。 From some push notification user must directly go to fragG with
findNavController().navigate(R.id.fragG)
, and when user tap back button he must go to fragF, but now is back to first fragment of navigation graph because fragB->fragC-fragD->fragE->fragF is not added to back stack.从一些推送通知中,用户必须使用
findNavController().navigate(R.id.fragG)
直接 go 到 fragG ,当用户点击返回按钮时,他必须 go 到 fragF,但现在回到导航图的第一个片段,因为 fragB-> fragC-fragD->fragE->fragF 未添加到后台堆栈。 It's possible to add this frag to stack when user navigate to last an press back button?当用户导航到最后一个按下后退按钮时,可以将此片段添加到堆栈吗? Thanks.
谢谢。
Google team is working on the backstack issue Google 团队正在处理 backstack 问题
Issue tracker: https://issuetracker.google.com/issues/80029773#comment112问题跟踪器: https://issuetracker.google.com/issues/80029773#comment112
Meanwhile there is a workaround for it.同时有一个解决方法。 Check this repo: https://github.com/android/architecture-components-samples/blob/master/NavigationAdvancedSample/app/src/main/java/com/example/android/navigationadvancedsample/NavigationExtensions.kt
检查这个仓库:https://github.com/android/architecture-components-samples/blob/master/NavigationAdvancedSample/app/src/main/java/com/example/android/navigationadvancedsample/NavigationExtensions.kt
It's not an official answer but it works as a workaround.这不是官方答案,但它可以作为一种解决方法。
You can create the back stack manually by navigating sequentially.您可以通过顺序导航来手动创建后台堆栈。
fun openGFromPushNotification(){
navigate(R.id.fragB)
navigate(R.id.fragC)
navigate(R.id.fragD)
navigate(R.id.fragE)
navigate(R.id.fragF)
navigate(R.id.fragG)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.