如何在 android 导航编辑器中链接多个活动? [英] How do I link multiple activities in android navigation editor?

查看:26
本文介绍了如何在 android 导航编辑器中链接多个活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm learning android development and the navigation component, trying to link multiple activities as the document had written. But it seems like it's impossible to create action between two activities to a single navigation graph which was reasonable to me as the document had written.

NavController 及其导航图包含在单个活动中.因此,在迁移现有项目以使用导航架构组件时,通过为每个 Activity 中的目的地创建导航图,专注于一次迁移一个 Activity.

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.

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

So the question is what does the following sentence mean? I could add multiple activities to one navigation graph but couldn't add a link(action) between them.

然后可以通过将活动目的地添加到导航图中来链接单独的活动,替换整个代码库中 startActivity() 的现有用法.

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 中, 目的地是该图的出口点- 一旦您使用 navigate(R.id.your_activity_destination) 转到下一个活动,该 NavController 和图形不再处于活动状态(它位于后堆栈上的活动上,而不是新启动的活动上).

Since each NavController and navigation graph is contained within a single activity, an <activity> destination is an exit point from that graph - once you use navigate(R.id.your_activity_destination) to go to the next activity, that NavController and graph is no longer active (it is on the activity on the back stack, not the newly launched activity).

在您的第二个 Activity 中,您将拥有第二个导航图,其中包含任何其他 出站目的地,以进行进一步的活动.

On your second Activity, you would have a second navigation graph with any additional <activity> outbound destinations to go to further activities.

这篇关于如何在 android 导航编辑器中链接多个活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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