What does the dot mean?
most of the time I just write that:
<activity android:name="OneActivity" ...>...</activity>
But sometimes I see in the autogenerated file:
<activity android:name=".OtherActivity" ...>...</activity>
And also in the Docs for Service I see that they write
<manifest ... >
...
<application ... >
<service android:name=".ExampleService" />
...
</application>
</manifest>
But I never saw any differences in trying the one or the other.
If you take a look at above, there is package definition like
package="app.package.name"
The class name with the dot means that that class is under the defined package.
If you have another package like
app.package.name.another
and there is a class in that package, you have to defined class name like
<activity android:name=".another.activityname"
From the the Android Dev Guide < activity > reference
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 element. There is
no default. The name must be specified.
Credit: jaywon from Activity Name in android Manifest in Stack Overflow
You can find some differences if you create more than one package, android checks for the class in the default folder that you might have mentioned while creating project.
As for the service, it automatically appends "services" to the package name and looks for the service in it. so its more like relative and absolute paths, if you place your service in different package name, you will have to mention the whole package path with class name. It applies to receivers too..
For picking up any activity Android requires fully qualified name...
For that Our Manifest files has attribute (i.e. package="com.test")
So to make it fully qualified we put dot before activity name (i.e. android:name=".FirstActivity" )
If you do not want to use dot before every activity then simply put dot after your package attribute in manifest tag.(i.e. package="com.test. ") and write activity name without dot (i.e. android:name="FirstActivity" )
So that it can overall make a fully qualified name (i.e. com.test.FirstActivity)
The dot before the name means that it is a hidden file that will not be seen by others. You can see on youtube how to hide files by android cell.
Related
I am flutter developer and some Android settings confuses me.
What is the difference between android:label and android:name in AndroidManifest.xml??
<application
android:name="io.flutter.app.FlutterApplication"
android:label="flutterapp2"
android:icon="#mipmap/ic_launcher">
The
android:name="io.flutter.app.FlutterApplication"
is a default to a Flutter application & you should NOT edit this anyway (unless you created a class that extends FlutterApplication class).
The android:label is to define your app name, which is display in the installed application list.
If you want to change the app name in home screen, check android:label inside the <activity /> tag
For more information, check out the official documentation:
https://developer.android.com/guide/topics/manifest/application-element
android:name
The fully qualified name of an Application subclass
implemented for the application. When the application process is
started, this class is instantiated before any of the application's
components. The subclass is optional; most applications won't need
one. In the absence of a subclass, Android uses an instance of the
base Application class.
android:label
A user-readable label for the application as a whole, and a default
label for each of the application's components. See the individual
label attributes for , , ,
, and elements. The label should be set as a
reference to a string resource, so that it can be localized like other
strings in the user interface. However, as a convenience while you're
developing the application, it can also be set as a raw string.
According to https://developer.android.com/guide/topics/manifest/application-element
android:name
The fully qualified name of an Application subclass implemented for the application. When the application process is started, this
class is instantiated before any of the application's components.
The subclass is optional; most applications won't need one. In the absence of a subclass, Android uses an instance of the base
Application class.
android:label
A user-readable label for the application as a whole, and a default label for each of the application's components. See the
individual label attributes for , ,
, , and elements.
The label should be set as a reference to a string resource, so that it can be localized like other strings in the user interface.
However, as a convenience while you're developing the application, it
can also be set as a raw string.
android:name this is a class which will wxecute first time (this is not your app name ,this is a functional thing)
and
android:label this is name of app shown on icon which represent the app name
android name is the name of the package that you are defining for that project and android label is the default name for your application
The android documentation states the following and you may find the list of attributes here
android:name
The fully qualified name of an Application subclass implemented for the application. When the application process is started, this class is instantiated before any of the application's components.
The subclass is optional; most applications won't need one. In the absence of a subclass, Android uses an instance of the base Application class.
android:label
A user-readable label for the application as a whole, and a default label for each of the application's components. See the individual label attributes for , , , , and elements.
The label should be set as a reference to a string resource, so that it can be localized like other strings in the user interface. However, as a convenience while you're developing the application, it can also be set as a raw string.
I am busy reading up of fully qualified names and packets etc,
In my project I have broken everything up into packages just to try and organize my project, but I have now realized this doesn't quite fit with the android manifest element as you can only provide one package?
Can I have multiple packages in my project like so?
You should specify a main package, and that package may have as many sub-packages as you like:
com.example.android could be a main package.
then you could specifiy the following:
com.example.android.activities
com.example.android.adapters
etc...
Of course, you may add classes to the 'root package' too without any hassle.
Check out Java package naming conventions for more info, Android follows these conventions as well.
You have to Specify a common package name for your application. eg:com.example.rhino68mobileapp and start every other packages by using this eg:com.example.rhino68mobileapp.utils
Yes you can use the multiple package in android, Only you have to play with access modifiers within your application, so that your one package class or object can communicate with other package class when desired.
Java provide different access modifiers:
Visible to the package. the default. No modifiers are needed.
Visible to the class only (private).
Visible to the world (public).
Visible to the package and all subclasses (protected).
For more read here
Edited:
You can define the main package(Application main package) and other package into your manifest like this:
<manifest package="com.example.mainPackage">
<application . . .>
<activity android:name=".packageOne.ActivityOne" . . . />
<activity android:name=".packageTwo.ActivityTwo" . . . />
<activity android:name=".packageThree.ActivityThree" . . . />
</application>
</manifest>
Yes you can.
The application package from the AndroidManifest.xml identifies your app.
But your Java code can be organized as you please.
I'm coming into a large preexisting Android project. The manifest looks something like this:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.company.group1.package1">
<application ... >
<activity android:name="com.company.group1.MyActivity />
<service android:name="com.company.group2.blah.MyService" />
<provider android:name="com.company.group3.etc.MyProvider" />
... more fully-qualified activities ...
</application>
</manifest>
Basically the entities are all over the place, package-wise, and all fully-qualified. This breaks all kinds of convention of course but somehow it works just fine. I've tried to find a statement from Google that this is a bad idea but I have not found any official recommendation against it or what kind of problems it would cause.
Renaming the package com.company is not a good option because the company has multiple apps.
My question is: Is there any reason other than convention to organize the project in a more sensible way? I anticipate pushback on a massive renaming because of issues with source control history and whatnot.
No, an activity's name doesn't have to be under the apk's main package. It is possible, for example, to specify an Activity that is defined in an external jar that uses a totally different package name.
The actual requirement according to the AndroidManifest.xml documentation is that an activity name "should be a fully qualified class name".
However, as the doc continues to mention, in most cases, there is a shorthand where you don't have to specify the fully qualified class name all the time. And this is by preceding the name with a '.'. (ie. "<activity android:name=".MyActivity />")
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>
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.
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".
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">
Is it required to start activity name with dot ('.') in manifest file.? for example activity
ContactManager starts with '.'
<activity android:name=".ContactManager" android:label="#string/app_name">
where as the activity ContactAdder is without dot
<activity android:name="ContactAdder" android:label="#string/addContactTitle">
in the manifest file of ContactManager sample http://developer.android.com/resources/samples/ContactManager/AndroidManifest.html
UPDATE: If activity name starts with . it is appended to package name to become fully qualified name, but what happens if it doesn't start with '.'
I got curious too, and went looking for it in the Android source code.
I found what seems to be the relevant code at the platform/frameworks/base repository, in the tools/aapt/Resource.cpp file. The relevant function is fullyQualifyClassName, called by massageManifest.
The rule it applies is explained in a comment block within the fullyQualifyClassName function:
// asdf --> package.asdf
// .asdf .a.b --> package.asdf package.a.b
// asdf.adsf --> asdf.asdf
Explaining this rule, we have:
If the name starts with a dot, always prefix it with the package.
If the name has a dot anywhere else, do not prefix it.
If the name has no dot at all, also prefix it with the package.
So, to answer your question: as long as there is no dot anywhere else, both ways of writing the activity name should have the same effect.
As an extra, the massageManifest function shows where this rule is applied:
In the application element, on the name and backupAgent attributes.
In the activity, service, receiver, provider, and activity-alias elements, on the name attribute.
In the activity-alias element, on the targetActivity attribute.
From the Android Dev Guide < activity > reference:
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 element.
There is no default. The name must be
specified.
Recently I understood the application package concept in Android and the answer for this question, thought i should share it.
If the application package(specified in manifest) is same as the java package in which Activity is present then it is not required to specify full package name in manifest for activities. If application package name is different from the java package name then activity name should be complete with package name.
This blog post give information about the application package and java packages in android.
http://blog.javia.org/android-package-name/comment-page-1/#comment-14063