Android Navigation 库深度链接:如何合成backstack [英] Android Navigation library deep linking: How to synthesise backstack

查看:25
本文介绍了Android Navigation 库深度链接:如何合成backstack的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Android 架构的导航组件,我有以下内容导航图

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

<代码>->[主页] ->[文章列表] ->[具体文章]

我还有一个指向 [Specific Article] 的深层链接.当它打开时,向上导航当前转到 [Home].

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

我想合成一个 backstack,以便向上导航而不是返回到 [文章列表](如果再次导航,则返回到 [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?

推荐答案

根据 NavDeepLinkBuilder 文档,Navigation 使用目的地的 startDestination 为合成返回堆栈.如果您将目的地分组到嵌套导航图中,嵌套图的 startDestination 和根图的 startDestination 被添加到返回堆栈中.这使您能够将 [文章列表] 作为嵌套图的 startDestination 以将其添加到您的返回堆栈中.

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.

然而,强烈建议让你的合成后栈尽可能小——虽然 2 或 3 的深度(如这里)很好,但不建议超出这个范围级别以避免用户必须反复点击和点击返回按钮才能返回启动器的情况.

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.

这篇关于Android Navigation 库深度链接:如何合成backstack的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆