在AndroidManifest.xml中活动名称 [英] Activity name in AndroidManifest.xml
问题描述
是否需要启动活动名称以点(。)清单文件。?例如活动 的ContactManager以'。
Is it required to start activity name with dot ('.') in manifest file.? for example activity ContactManager starts with '.'
<activity android:name=".ContactManager" android:label="@string/app_name">
在这里作为活动ContactAdder是没有点
where as the activity ContactAdder is without dot
<activity android:name="ContactAdder" android:label="@string/addContactTitle">
在的ContactManager样品清单文件<一个href="http://developer.android.com/resources/samples/ContactManager/AndroidManifest.html">http://developer.android.com/resources/samples/ContactManager/AndroidManifest.html
in the manifest file of ContactManager sample http://developer.android.com/resources/samples/ContactManager/AndroidManifest.html
更新:如果活动名称开头。会被添加到包名,成为完全合格的名字,但如果它不是以会发生什么。
UPDATE: If activity name starts with . it is appended to package name to become fully qualified name, but what happens if it doesn't start with '.'
推荐答案
我也好奇,去寻找它在Android源$ C $ C。
I got curious too, and went looking for it in the Android source code.
我发现了什么似乎是相关的code。在平台/框架/基
库,在工具/ AAPT /资源的.cpp
文件。相关的功能是 fullyQualifyClassName
,称为 massageManifest
。
I found what seems to be the relevant code at the platform/frameworks/base
repository, in the tools/aapt/Resource.cpp
file. The relevant function is fullyQualifyClassName
, called by massageManifest
.
适用该规则的 fullyQualifyClassName
函数内的注释块说明:
The rule it applies is explained in a comment block within the fullyQualifyClassName
function:
// asdf --> package.asdf
// .asdf .a.b --> package.asdf package.a.b
// asdf.adsf --> asdf.asdf
在解释这条规则,我们有:
Explaining this rule, we have:
- 如果名字的开头一个点,总是用$装P $ PFIX吧。
- 如果该名有一个点在其他地方,不要preFIX吧。
- 如果该名称没有点可言,也有$装P $ PFIX吧。
因此,要回答你的问题:只要没有点其他地方,写活动名称的两种方式应该有同样的效果。
So, to answer your question: as long as there is no dot anywhere else, both ways of writing the activity name should have the same effect.
作为一个额外的 massageManifest
函数表示在应用此规则:
As an extra, the massageManifest
function shows where this rule is applied:
- 在
应用程序
元素,在名称
和backupAgent
属性。 - 在
活动
,服务
,接收
,提供商
和活动别名
元素,在名称
属性。 - 在
活动别名
元素,在targetActivity
属性。
- In the
application
element, on thename
andbackupAgent
attributes. - In the
activity
,service
,receiver
,provider
, andactivity-alias
elements, on thename
attribute. - In the
activity-alias
element, on thetargetActivity
attribute.
这篇关于在AndroidManifest.xml中活动名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!