Thursday 3 December 2020

Multiple Navigation Graphs in Android and Deep Links

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.



from Multiple Navigation Graphs in Android and Deep Links

No comments:

Post a Comment