Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Navigation library deep linking: How to synthesise backstack

Using Android Architecture's Navigation component, I have the following navigation graph

-> [Home] -> [Articles List] -> [Specific Article]

I also have a deeplink to [Specific Article]. When it is opened, navigating up currently goes to [Home].

I'd like to synthesise a backstack such that navigating up instead goes back to [Articles List] (and then on to [Home] if navigating again).

What is the Navigation way of doing this?

like image 204
Tom Avatar asked May 14 '18 22:05

Tom


People also ask

How do you create a deep link?

To use the tool, log in to your Adjust dashboard and open the Menu, where you'll see the 'Deeplink Generator' as an option. Click to open, and you'll find a page to input the information required to create your deep link. Then simply copy and paste into whichever campaign you've set up.

How do you make a deep link in HTML?

You can use <a href="yourpage.com#pt1"> to define the link and include the tag in your page where you want the link to point to. Could you please update the question with what you have tried? This should work.

How do Deeplinks work?

With deferred deep links, a user who clicks an ad but who doesn't have your app installed can be directed to the App store instead. Then, because the data from their click is logged, that user is automatically sent to the intended destination after they've installed the app.


2 Answers

Per the NavDeepLinkBuilder documentation, Navigation uses the startDestination of the destination for the synthetic back stack. If you Group destinations into a nested navigation graph, both the startDestination of the nested graph and the startDestination of the root graph are added to the back stack. This gives you the ability to have [Articles List] as the startDestination of the nested graph to add it to your back stack.

However, it is strongly recommended to keep your synthetic back stack as small as possible - while a depth of 2 or 3 (as here) is fine, it is not recommended to go much beyond that level to avoid cases where users have to repeatedly tap and tap the back button to get back to the launcher.

like image 158
ianhanniballake Avatar answered Sep 17 '22 14:09

ianhanniballake


The documentation implies that my original solution should work.

When a user uses the Back button from a deep link destination, they navigate back up the navigation stack just as though they entered your app from the app’s entry point.

In addition, ianhanniballake's answer doesn't produce expected results (the deeplinked fragment is not opened).

I have created an issue on google's tracker for both these problems: https://issuetracker.google.com/issues/79734195

like image 37
Tom Avatar answered Sep 19 '22 14:09

Tom