开发者

Android Manifest: Why sometimes ".<classname>" instead of just "<classname>"?

开发者 https://www.devze.com 2023-04-02 21:14 出处:网络
What does the dot mean? most of the time I just write that: <activity android:name=\"OneActivity\" ...>...</activity>

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开发者_StackOverflow" />
      ...
  </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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号