如何在 android 导航编辑器中 link 多个活动?

How do I link multiple activities in android navigation editor?

我正在学习 android 开发和导航组件,尝试 link 多个活动,如 document 所写。但似乎不可能在两个活动之间创建对单个导航图的操作,这对我来说是合理的,正如文档所写的那样。

The NavController and its navigation graph is contained within a single activity. Therefore, when migrating an existing project to use the Navigation Architecture Component, focus on migrating one Activity at a time by creating a navigation graph for the destinations within each Activity.

那么问题来了下面这句话是什么意思?我可以将多个活动添加到一个导航图中,但无法在它们之间添加 link(action)。

Separate Activities can then be linked by adding activity destinations to the navigation graph, replacing existing usages of startActivity() throughout the code base.

由于每个 NavController 和导航图都包含在单个 activity 中,<activity> 目的地是该图的出口点 - 一旦您使用 navigate(R.id.your_activity_destination) 转到下一个activity,NavController 和图形不再处于活动状态(它在返回堆栈的 activity 上,而不是新启动的 activity)。

在您的第二个 Activity 上,您将有第二个导航图,其中包含任何其他 <activity> 出站目的地,以便进行进一步的活动。