Android Manifest: Why sometimes “.” ins

2019-04-29 10:43发布

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.

5条回答
老娘就宠你
2楼-- · 2019-04-29 11:07

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)

查看更多
做个烂人
3楼-- · 2019-04-29 11:18

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..

查看更多
等我变得足够好
4楼-- · 2019-04-29 11:19

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"
查看更多
我命由我不由天
5楼-- · 2019-04-29 11:27

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

查看更多
Explosion°爆炸
6楼-- · 2019-04-29 11:31

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.

查看更多
登录 后发表回答