1

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?

Community
  • 1
  • 1
AdnanJ
  • 11
  • 1

1 Answers1

3

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 :)

Liaz Kamper
  • 108
  • 1
  • 7
  • Hi @Liaz, thanks for answering. Sorry I could not answer before, but this approach is not suitable for me as the deep link is called when clicking on a link from e-mail (it is not created in the app itself), and we handle that deep-link solely in navigation xml graph. Do you know some other approach to this problem? And btw, we navigate from register fragment in step #2 like from any other fragment using navigation directions: `RegisterFragmentDirections.actionRegisterFragmentTo...` – AdnanJ Apr 14 '20 at 14:21