Leading point in android: is the name really required?

Possible duplicate:
What is a "point" for activity registration

In all Android names, Activities, Services, etc. it all starts from the point:

<activity android:name=".MyActivity" /> 

I forgot to do this in all Android projects, but they work great.

My question is: is this leading point really needed?

EDIT: Here is a small example of a snapshot from one of my applications. This app works perfectly. It does not use qualified names and does not use periods:

 <activity android:exported="false" android:name="Tankvorgaenge" > <intent-filter> <action android:name="android.intent.action.SEARCH" /> </intent-filter> <meta-data android:name="android.app.searchable" android:resource="@xml/searchable" /> </activity> <activity android:name="Tankvorgangdetails" /> <activity android:name="Tankvorgangdetailsbearbeiten" /> <activity android:name="TankvorgangUebersicht" /> <activity android:name="Verbrauch" /> <service android:name="MyService" /> 
+8
android manifest
source share
4 answers

Omitting the point and not fully qualifying the name of the package / class will work if and only if the specified class is not part of the subpackage in your application.

If your application package name is com.example.myapp , and you have the activity class com.example.myapp.MyActivity :

  • android:name="MyActivity" will work.
  • android:name=".MyActivity" will work.
  • android:name="com.example.myapp.MyActivity" will work.

But if you have the same application package and activity class in a subpackage inside the source tree, for example com.example.myapp.myactivities.MyActivity , everything changes.

  • android:name=".myactivities.MyActivity" will work
  • android:name="com.example.myapp.myactivities.MyActivity" will work
  • android:name="MyActivity" will not work
  • android:name="myactivities.MyActivity" will not work

3 does not work, because it will mean that the class name that you mean is actually com.example.myapp.MyActivity , as in the first example above. A class with this name will not be found, and you will receive an error message.

4 does not work, because it looks like the full name of the class, that is, the system will interpret it as meaning that myactivities.MyActivity is the full name, not the real name com.example.myapp.myactivities.MyActivity .

You need a leading point here to make it clear that you are using a relative path, not an absolute path. If you specify only the class name without package information, the system will report that the class is at the root of your application package hierarchy.

+19
source share

The point is to use the relative path to the application, gives package_name . You can replace .MyActivity with com.yourActivityPackage.MyActivity

+2
source share

Yes, activity[android:name] must either specify a fully qualified package.Class , or if it starts with a period, then it is added to the application package.

See doc

+1
source share

It is required. This is an abbreviation for the package name. android: the name must indicate the full name of the class. By entering a leading point, we can indicate that the next class name is in the "package" declared above in the manifest.

0
source share

All Articles