AndroidManifest.xml中的活动名称是否必须以点开头? [英] Is the activity name in AndroidManifest.xml required to start with a dot?
问题描述
是否需要在清单文件中以点('.')开头的活动名称?例如活动 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">
ContactContacter活动中没有点
where as the activity ContactAdder is without dot
<activity android:name="ContactAdder" android:label="@string/addContactTitle">
在ContactManager示例的清单文件中 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源代码中寻找它.
I got curious too, and went looking for it in the Android source code.
我在tools/aapt/Resource.cpp
文件的platform/frameworks/base
存储库中找到了似乎相关的代码.相关功能是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
解释此规则,我们有:
- 如果名称以点开头,请始终在包装之前添加前缀.
- 如果该名称在其他任何地方都有点,请不要在其前添加前缀.
- 如果该名称完全没有点,也请在名称前加上包装.
因此,要回答您的问题:只要其他地方没有点,两种书写活动名称的方式都应具有相同的效果.
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:
- 在
application
元素的name
和backupAgent
属性上. - 在
activity
属性的activity
,service
,receiver
,provider
和activity-alias
元素中. - 在
activity-alias
元素的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屋!