Android Navigation - After deeplink navigation to second fragment, open first fragment in the same graph, but from another navigation graph

淺唱寂寞╮ 提交于 2020-04-16 02:58:13

问题


In my navigation, I have something like this:

Navigation graph mock image

  1. When I open registrationFragment (in entry_graph) from a deep-link, and finish registration, I am navigated to main_graph (MainFragment).
  2. From there, I can access to menuFragment and click on logOut, which calls:

    MainFragmentDirections.actionMainFragmentToEntryFragment()

  3. 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.

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.

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?


回答1:


How do navigate in step#2? I tried the same flow and it worked when I used the code described here.

Basically this is the code

PendingIntent pendingIntent = new NavDeepLinkBuilder(context)
.setGraph(R.navigation.nav_graph)
.setDestination(R.id.android)
.setArguments(args)
.createPendingIntent();

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.

Hope it works for you :)



来源:https://stackoverflow.com/questions/60618015/android-navigation-after-deeplink-navigation-to-second-fragment-open-first-fr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!