AndroidManifest.xml中的活动名称是否必须以点开头? [英] Is the activity name in AndroidManifest.xml required to start with a dot?

查看:99
本文介绍了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">

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

解释此规则,我们有:

  1. 如果名称以点开头,请始终在包装之前添加前缀.
  2. 如果该名称在其他任何地方都有点,请不要在其前添加前缀.
  3. 如果该名称完全没有点,也请在名称前加上包装.

因此,要回答您的问题:只要其他地方没有点,两种书写活动名称的方式都应具有相同的效果.

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元素的namebackupAgent属性上.
  • activity属性的activityservicereceiverprovideractivity-alias元素中.
  • activity-alias元素的targetActivity属性上.
  • In the application element, on the name and backupAgent attributes.
  • In the activity, service, receiver, provider, and activity-alias elements, on the name attribute.
  • In the activity-alias element, on the targetActivity attribute.

这篇关于AndroidManifest.xml中的活动名称是否必须以点开头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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