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

后端 未结 3 1811
一向
一向 2020-12-08 14:37

Is it required to start activity name with dot (\'.\') in manifest file.? for example activity ContactManager starts with \'.\'



        
相关标签:
3条回答
  • 2020-12-08 14:46

    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.
    0 讨论(0)
  • 2020-12-08 14:49

    Recently I understood the application package concept in Android and the answer for this question, thought i should share it.

    If the application package(specified in manifest) is same as the java package in which Activity is present then it is not required to specify full package name in manifest for activities. If application package name is different from the java package name then activity name should be complete with package name.

    This blog post give information about the application package and java packages in android.

    http://blog.javia.org/android-package-name/comment-page-1/#comment-14063

    0 讨论(0)
  • 2020-12-08 14:57

    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.

    0 讨论(0)
提交回复
热议问题