Android导航-在对第二个片段进行深度链接导航之后,在同一图中但从另一个导航图中打开第一个片段 [英] Android Navigation - After deeplink navigation to second fragment, open first fragment in the same graph, but from another navigation graph
问题描述
在我的导航中,我有这样的东西:
In my navigation, I have something like this:
- 当我从深层链接中打开registrationFragment(在entry_graph中)并完成注册时,将导航至main_graph(MainFragment).
-
从那里,我可以访问menuFragment并单击logOut,这将调用:
- When I open registrationFragment (in entry_graph) from a deep-link, and finish registration, I am navigated to main_graph (MainFragment).
From there, I can access to menuFragment and click on logOut, which calls:
MainFragmentDirections.actionMainFragmentToEntryFragment()
它将打开registrationFragment而不是loginFragment.我不希望这样,因为loginFragment是该图中的主片段.
It opens the registrationFragment instead of loginFragment. I do not expect that since loginFragment is the home fragment on that graph.
当我进行类似的导航但不使用深层链接时,它会按预期运行,它将打开该图中的第一个片段,但是通过这种深层链接流程,它将始终打开由深层链接打开的片段.链接,在导航图中的位置没有任何关系.
When I have similar navigation but not using deep-links, it works as it should, it opens the first fragment in that graph, but with this deep-link flow, it always opens the fragment that was opened by the deep-link, no mater where it is positioned in the navigation graph.
我已经在SO和Web上搜索了解决方案,但是在任何地方都找不到相同的问题.
I have searched for solutions on SO and web, but could not find the same problem anywhere.
我尝试过手动将其从后堆栈和类似的解决方案中删除,但是我无法成功,它总是打开由深度链接首先打开的片段.
I have tried removing it manually from back-stack and similar solutions but I could not succeed, it always opens the fragment that was opened by the deep-link in first place.
我正在使用导航版本2.1.0,但是在最新的2.2.0版本上对此流进行了测试,并且其行为相同.
I am using navigation version 2.1.0, but tested this flow on the currently latest 2.2.0 and it behaves the same.
有人知道这种导航流程是否有解决方案吗?
Does anybody knows if there is a solution for this navigating flow?
推荐答案
如何在步骤2中导航?我尝试了相同的流程,并且在此处.
How do navigate in step#2? I tried the same flow and it worked when I used the code described here.
基本上这是代码
PendingIntent pendingIntent = new NavDeepLinkBuilder(context)
.setGraph(R.navigation.nav_graph)
.setDestination(R.id.android)
.setArguments(args)
.createPendingIntent();
如文档中所述,当您使用Intent进行导航时,将重置后向堆栈,并使用每个先前图形的 home片段进行填充. 只需确保在nav_graph xml中正确正确地描述了所需的后台堆栈-每个 home片段都会打开一个新的缩进.
As described in the doc, when you navigate using intent, the back-stack is reset, and populated with the home fragment of each previous graph. Just make sure the required back-stack actually described correctly in the nav_graph xml - each home fragment opens a new indent.
希望它对您有用:)
这篇关于Android导航-在对第二个片段进行深度链接导航之后,在同一图中但从另一个导航图中打开第一个片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!