57

I'm kind of a noob at programming for the Android OS. I noticed in the books I have been reading that the authors have placed a "dot" in front of the activity name when registering their activities in the manifest. I've looked around the Android developer site and I can't figure out why we need the "dot". Does the "dot" actually server a purpose? Do I need it? I have included an example below. Notice the "dot" before "NewActivity":

<activity android:name=".NewActivity"></activity>
Cristian
  • 198,401
  • 62
  • 356
  • 264
Cavachon
  • 2,819
  • 4
  • 21
  • 20

3 Answers3

44

As you have noticed the point is not necessary but it basically means: the activity class lives in the same package of the app. So, if your app package is: com.my.package then:

  • .YourActivity means that your class is inside com.my.package.
  • YourActivity means that your class is inside com.my.package (same as above).
  • .activities.YourActivity means that your class is inside com.my.package.activitites.
  • You can even do something like: com.my.package.activities.YourActivity which is useful when you want to have different versions of your app and use Ant to change the references to the package automatically.
Cristian
  • 198,401
  • 62
  • 356
  • 264
  • 6
    The documentation seems to say that you need the leading dot to get the package name pre-pended. It seems an accident that a bare "YourActivity" works at all. Why isn't it interpreted as a class name in the (much maligned) default package? – Ted Hopp Jan 30 '11 at 09:33
  • as documentation is not same implying what source code is doing so it can be termed as an accident. – Sachin Gupta May 02 '16 at 11:56
  • and what if I actually want my activity to be in default package? – Sachin Gupta May 02 '16 at 11:57
32

http://developer.android.com/guide/topics/manifest/activity-element.html#nm

android:name
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 <manifest>.

So given ApplicationManifest.xml:

<manifest 
    ...
    package="com.stackoverflow.android.geotask"
    ...>
    <application ...>
        <activity android:name=".view.TaskListListView" ...>
        ...
    </application>
</manifest> 

then since android:name=".view.TaskListListView" has a leading period, so it is interpreted as android:name="com.stackoverflow.android.geotask.view.TaskListListView".

Bert F
  • 85,407
  • 12
  • 106
  • 123
  • 1
    I think it's best to always include the fully qualified class name, this way, the confusing dot can be avoided. – Vahid Amiri Nov 11 '16 at 20:48
4

That dot will append your package in your application manifest.

If your package name is com.app.demo.

<activity android:name=".HelloWorldActivity">

It means that Activity is lying inside demo package.

You can replace this with

<activity android:name="com.app.demo.HelloWorldActivity">
JoxTraex
  • 13,423
  • 6
  • 32
  • 45
Gevaria Purva
  • 552
  • 5
  • 15