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

查看:59
本文介绍了如何在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天全站免登陆