Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Leading dot in android:name really required? [duplicate]

Possible Duplicate:
What's the “dot” for when registering an Activity

In all Android examples names of Activities, Services, etc. all start with a dot:

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

I forgot to do this in all Android projects - but they do work perfect.

My question: Is this leading dot really required?

EDIT: Here's a small snapshot example from one of my apps. This app works perfect. It doesn't use qualified names and it doesn't use dots:

<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" />
like image 320
Harald Wilhelm Avatar asked Aug 26 '12 15:08

Harald Wilhelm


People also ask

How do you fix you need to use a different package name because COM example is restricted?

To rename the package name, In eclipse right click on the project in project explorer. Then Android Tools > rename Aplication Package name. Then enter the new package name.

What is the name of label in Android?

The android:label is to define your app name, which is display in the installed application list.

How do I change the name of an Android app?

Go to the app > manifests > AndroidManifest. xml file and change the android:label field in your application node in AndroidManifest.


2 Answers

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

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

  1. android:name="MyActivity" will work.
  2. android:name=".MyActivity" will work.
  3. android:name="com.example.myapp.MyActivity" will work.

But if you have the same application package and an activity class in a subpackage within your source tree such as com.example.myapp.myactivities.MyActivity things change.

  1. android:name=".myactivities.MyActivity" will work
  2. android:name="com.example.myapp.myactivities.MyActivity" will work
  3. android:name="MyActivity" will not work
  4. android:name="myactivities.MyActivity" will not work

3 doesn't work because that will infer that the class name you mean is actually com.example.myapp.MyActivity like in the first example above. A class with this name won't be found and you'll get an error.

4 doesn't work because it looks like a fully qualified class name, that is the system will interpret it to mean that myactivities.MyActivity is the fully qualified name itself, not the real name of com.example.myapp.myactivities.MyActivity.

You need the leading dot here to clarify that you're using a relative path, not an absolute path. If you specify just a class name with no package info at all, the system infers that the class is at the root of your application package hierarchy.

like image 178
adamp Avatar answered Nov 29 '22 16:11

adamp


The dot is to use the relative path to the app gives package_name. You can replace .MyActivity with com.yourActivityPackage.MyActivity

like image 27
Brais Gabin Avatar answered Nov 29 '22 18:11

Brais Gabin