gpt4 book ai didi

android - 在 list 文件中定义 Activity 的正确语法是什么

转载 作者:可可西里 更新时间:2023-11-01 18:59:09 24 4
gpt4 key购买 nike

将 Activity 添加到 AndroidManifest.xml 的正确方法是什么?

其实我在很多地方都看到过一个activity定义为

<activity 
android:name="MyFirstActivity"
android:label="@string/title_first_activity">
</activity>

还有一些地方

<activity 
android:name=".MySecondActivity"
android:label="@string/title_second_activity">
</activity>

我只是想知道放一个点 (.) 是否是将 Activity 添加到 list 文件的正确方法。

我看了很多帖子,但没有找到确切的解决方案。 This建议点 (.) 不是必需的,而 this建议使用点 (.)。那么怎样才是正确的做法呢?

最佳答案

点表示您的包名称。这是更短的声明类型。

If you define a subclass, as you almost always would for the component classes (Activity, Service, BroadcastReceiver, and ContentProvider), the subclass is declared through a name attribute. The name must include the full package designation. For example, an Service subclass might be declared as follows:

<manifest . . . >
<application . . . >
<service android:name="com.example.project.SecretService" . . . >
. . .
</service>
. . .
</application>
</manifest>

However, as a shorthand, if the first character of the string is a period, the string is appended to the application's package name (as specified by the element's package attribute). The following assignment is the same as the one above:

<manifest package="com.example.project" . . . >
<application . . . >
<service android:name=".SecretService" . . . >
. . .
</service>
. . .
</application>
</manifest>

When starting a component, Android creates an instance of the named subclass. If a subclass isn't specified, it creates an instance of the base class.

http://developer.android.com/guide/topics/manifest/manifest-intro.html 声明类名

关于android - 在 list 文件中定义 Activity 的正确语法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11450421/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com