Abbreviation of activity implementation class in android: name of Activity

Source: Internet
Author: User

<Manifest xmlns: android = "http://schemas.android.com/apk/res/android"
Package = "com. example. android. apis">


<Activity android: name = "ApiDemos">
<Intent-filter>
<Action android: name = "android. intent. action. MAIN"/>
<Category android: name = "android. intent. category. DEFAULT"/>
<Category android: name = "android. intent. category. LAUNCHER"/>
</Intent-filter>
</Activity>


<Activity android: name = ". app. HelloWorld" android: label = "@ string/activity_hello_world">
<Intent-filter>
<Action android: name = "android. intent. action. MAIN"/>
<Category android: name = "android. intent. category. SAMPLE_CODE"/>
</Intent-filter>
</Activity>


The android: name attribute of the activity component is abbreviated as a class name. but why android: anem = "ApiDemos" in <activity android: name = "ApiDemos"> instead of android: anem = ". what about ApiDemos? What about the android: name values of all subsequent Activity components in the ". ClassName" format? Google immediately queries the description of the android: name attribute value, but does not find the description that "." is not added before the class name!

However, let's test and verify the program. The results "ApiDemos" and ". ApiDemos" both run the program correctly. Is there a "." before the class name the same as? The ". ClassName" format is clearly described in this document! So I removed the first "." In the value string of android: name of other activities and ran the program again, but it became strange! Depressed! After repeated tests, we found a rule:

If the package attribute is specified in manifest, for example. android. sample ", if the implementation class of the activity is also in this package, then android: name is the name of the implemented class. It does not matter if the class name is not added before it, if the Implementation class of the activity is in the sub-package of the default package, then this ". "is mandatory. For example, the implementation of activity is com. android. sample. app. dialogActivity, android: name must be written. app. dialogActivity or com. android. sample. app. dialogActivity. If you only write app. DialogActivity, an error is returned.

Haha, it seems that the design of Android is a little failed. The uniform format and mandatory shorthand must have! In the official example, this design is still specially designed. Is it a special purpose?

Manage it! Whether the subclass of the Activity is in the default package or under the sub-package of the default package, the abbreviated class name is ". ClassName!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.