在AndroidManifest.xml中活动名称 [英] Activity name in AndroidManifest.xml

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

  1. 如果名字的开头一个点,总是用$装P $ PFIX吧。
  2. 如果该名有一个点在其他地方,不要preFIX吧。
  3. 如果该名称没有点可言,也有$装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 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天全站免登陆