我必须在 Android Manifest 中指定父活动名称吗? [英] Must I specify the parent activity name in the Android Manifest?

查看:44
本文介绍了我必须在 Android Manifest 中指定父活动名称吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个活动可以启动另一个活动.
我是否必须在 Android Manifest 中指定父活动?我问这个是因为可能还有其他活动也会启动这个活动,所以我应该指定所有活动吗?

I have an activity that starts another activity.
Is it mandatory that I specify the parent activity in the Android Manifest? Im asking this because there might be other activities that will start this one as well, so should I specify all of them?

android:parentActivityName="com.example.myfirstapp.MainActivity" 

推荐答案

根据 docs -> 部分 android:parentActivityName:

As per docs -> section android:parentActivityName:

系统读取此属性以确定当用户按下操作栏中的向上按钮时应启动哪个活动.系统还可以使用此信息与 TaskStackBuilder 合成一个返回的活动堆栈.

The system reads this attribute to determine which activity should be started when the user presses the Up button in the action bar. The system can also use this information to synthesize a back stack of activities with TaskStackBuilder.

因此您只需要指定是否要使用向上导航(而不是通过后退按钮导航)或 TaskStackBuilder.在其他情况下,您不需要它.

So you only need to specify that if you're going to use up-navigation (as opposed to navigation by back button) or TaskStackBuilder. In other cases, you don't need it.

点击此处了解向上导航:http://developer.android.com/design/patterns/navigation.html

Check in here about up-navigation: http://developer.android.com/design/patterns/navigation.html

这篇关于我必须在 Android Manifest 中指定父活动名称吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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