Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

android

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

like image 793
Suresh Avatar asked Aug 31 '10 10:08

Suresh


People also ask

What is true about the AndroidManifest XML file?

xml file contains information of your package, including components of the application such as activities, services, broadcast receivers, content providers etc. It performs some other tasks also: It is responsible to protect the application to access any protected parts by providing the permissions.

What is contained in the AndroidManifest XML?

Every app project must have an AndroidManifest. xml file (with precisely that name) at the root of the project source set. The manifest file describes essential information about your app to the Android build tools, the Android operating system, and Google Play.

What does AndroidManifest XML contain Mcq?

The manifest explains what the application consists of and glues everything together. The XML file that contains all the text that your application uses.


2 Answers

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.
like image 177
CesarB Avatar answered Oct 12 '22 03:10

CesarB


From the Android Dev Guide < activity > reference:

The name of the class that implements the activity, a subclass of Activity. The attribute value should be a fully qualified class name (such as, "com.example.project.ExtracurricularActivity"). However, as a shorthand, if the first character of the name is a period (for example, ".ExtracurricularActivity"), it is appended to the package name specified in the element. There is no default. The name must be specified.

like image 45
jaywon Avatar answered Oct 12 '22 02:10

jaywon