Android Navigation library deep linking: How to synthesise backstack

南楼画角 提交于 2021-02-06 08:51:47

问题


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?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/50339826/android-navigation-library-deep-linking-how-to-synthesise-backstack

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