Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
264 views
in Technique[技术] by (71.8m points)

android - Is the activity name in AndroidManifest.xml required to start with a dot?

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">

where as the activity ContactAdder is without dot

<activity android:name="ContactAdder" android:label="@string/addContactTitle">

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 '.'

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I got curious too, and went looking for it in the Android source code.

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.

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. If the name starts with a dot, always prefix it with the package.
  2. If the name has a dot anywhere else, do not prefix it.
  3. If the name has no dot at all, also prefix it with the package.

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.


As an extra, the massageManifest function shows where this rule is applied:

  • 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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...