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" />
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.
The android:label is to define your app name, which is display in the installed application list.
Go to the app > manifests > AndroidManifest. xml file and change the android:label field in your application node in AndroidManifest.
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
:
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 an activity class in a subpackage within your source tree such as com.example.myapp.myactivities.MyActivity
things change.
android:name=".myactivities.MyActivity"
will workandroid:name="com.example.myapp.myactivities.MyActivity"
will workandroid:name="MyActivity"
will not work
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.
The dot is to use the relative path to the app gives package_name
. You can replace .MyActivity
with com.yourActivityPackage.MyActivity
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With