Android 导航库深度链接:如何合成 backstack
Android Navigation library deep linking: How to synthesise backstack
使用Android Architecture's Navigation component,我有以下导航图
-> [Home] -> [Articles List] -> [Specific Article]
我还有 [Specific Article]
的深层链接。打开后,向上导航当前转到 [Home]
。
我想合成一个后退堆栈,以便向上导航而不是返回到 [Articles List]
(然后如果再次导航则返回到 [Home]
)。
这样做的导航方式是什么?
根据NavDeepLinkBuilder documentation, Navigation uses the startDestination
of the destination for the synthetic back stack. If you Group destinations into a nested navigation graph,嵌套图的startDestination
和根图的startDestination
都被添加到返回堆栈。这使您能够将 [Articles List]
作为嵌套图的 startDestination
以将其添加到返回堆栈。
但是,强烈建议让你的合成后台堆栈尽可能小——虽然 2 或 3 的深度(如此处)很好,但不推荐远远超出该级别,以避免用户必须反复点击并点击后退按钮才能返回启动器的情况。
documentation 暗示我的原始解决方案应该有效。
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.
此外,ianhanniballake 的回答没有产生预期的结果(深度链接片段未打开)。
我在 google 的跟踪器上针对这两个问题创建了一个问题:https://issuetracker.google.com/issues/79734195
使用Android Architecture's Navigation component,我有以下导航图
-> [Home] -> [Articles List] -> [Specific Article]
我还有 [Specific Article]
的深层链接。打开后,向上导航当前转到 [Home]
。
我想合成一个后退堆栈,以便向上导航而不是返回到 [Articles List]
(然后如果再次导航则返回到 [Home]
)。
这样做的导航方式是什么?
根据NavDeepLinkBuilder documentation, Navigation uses the startDestination
of the destination for the synthetic back stack. If you Group destinations into a nested navigation graph,嵌套图的startDestination
和根图的startDestination
都被添加到返回堆栈。这使您能够将 [Articles List]
作为嵌套图的 startDestination
以将其添加到返回堆栈。
但是,强烈建议让你的合成后台堆栈尽可能小——虽然 2 或 3 的深度(如此处)很好,但不推荐远远超出该级别,以避免用户必须反复点击并点击后退按钮才能返回启动器的情况。
documentation 暗示我的原始解决方案应该有效。
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.
此外,ianhanniballake 的回答没有产生预期的结果(深度链接片段未打开)。
我在 google 的跟踪器上针对这两个问题创建了一个问题:https://issuetracker.google.com/issues/79734195