47

I have 3 Activities: Main, Login, Wizard.

For each Activity I have separate Navigation Graph with fragment destinations.

Main Nav Graph has also Login Activity destination to launch Login screen on logout.

App seems to work correctly when launched from Action.MAIN launcher intent.

BUT I experience problem when using Deep Link. I would like to add URI to Login Nav Graph (Change Password Fragment). This Nav Graph uses separate NavHostFragment. I have used 2 approaches.

  1. Directly add Deep Link to Change Password Fragment Destination in Login Nav Graph -> Deep Links navigate only to START DESTINATION (Login Fragment Destination). Here also Back button does NOT work correctly, i.e. finishing app instead returning to Main Nav Graph Main Destination.
  2. Add Deep Link to Login Activity Destination in Main Nav Graph and again and here Back button does work correctly, I as expected landed on Login Fragment Destination. BUT here I want to manually navigate to Change Password Fragment Destination and I experience another problem, i.e. the Intent Action.View with Uri data is not delivered into this Login Activity destination. It is only delivered to Main Activity which host Main Nav Graph.

To sum up. I think this Deep link behaviour between multiple Nav Graphs connected by Activity Destinations does NOT work as it should. I do not know whether there are any solutions to this.

Can I retrieve Deep Link Arguments (Uri data) from NavController somehow? Or the only solution is to get it from getIntent().data? Here as I say this Intent is not forwarded to final destination Activity, but only to first Activity in the created stack of Activities.

Now I returned to manually handling Deep Links without Android Navigation Architecture as it seems useless if there is more complex navigation structure than single Nav Graph with single Activity and only inner Fragment navigation.

Michał Ziobro
  • 10,759
  • 11
  • 88
  • 143
  • 1
    So you have a login activity that has deep links and has a `` element in the manifest as per [the documentation](https://developer.android.com/guide/navigation/navigation-deep-link#implicit) and when you trigger a deep link that opens the right activity, but the wrong destination? Please include your login graph and how you are triggering that deep link. – ianhanniballake Dec 04 '20 at 05:22
  • Hey Please Check this link i think it will help you with your issue https://developer.android.com/guide/navigation/navigation-multi-module – Jaspalsinh Gohil Mar 15 '23 at 06:46

1 Answers1

0

You should use only one main graph to include your graphs as written in the docs.

And related to unexpected back press result, use NavDeepLinkRequest.

val request = NavDeepLinkRequest.Builder
    .fromUri("android-app://example.google.app/settings_fragment_two".toUri())
    .build()
findNavController().navigate(request)

As stated in the docs,

Unlike navigating using action or destination IDs, you can navigate to any URI in any graph, even across modules.

When navigating using URI, the back stack is not reset. This behavior is unlike explicit deep link navigation, where the back stack is replaced when navigating.

To navigate among modules, make sure you use the main navController (of the main graph). You can call it from other modules by tag anyway.