Intent Service 在 Android Manifest 中如何声明?

36

简单明了的问题:

在Android Manifest中,IntentService是作为常规服务声明的,还是有其他方法?我尝试搜索了一下,但是没有找到答案。

这是一个普通服务声明的示例:

 <service
                android:name=".NameOfService">
 </service>

谢谢

2个回答

72
在您的清单文件中,您声明了一个服务,并使用 android:name=".Communication" 进行标识。这意味着您的服务类应该位于 com.exercise.AndroidClient.Communication 中。
请检查包名是否正确。请注意,“.”(点)表示您包的根目录(即在清单文件中声明的包)。因此,例如,如果您的包名为 com.exercise.AndroidClient,并且您的服务类位于 com.exercise.AndroidClient.services.Communication 中,则需要像这样声明服务:
<service android:enabled="true" android:name=".services.Communication" />

或者指定完整的包:

<service android:enabled="true" android:name="com.exercise.AndroidClient.services.Communication" />

如何在清单文件中声明本地服务,例如活动类名为“TestActivity”,并且该类内部有“MyService”。 - Hiren Dabhi
2
“enabled” 有什么作用? - IgorGanapolsky

16

没有任何区别,与常规的相同。

这是我的。

<service android:name=".MyIntentService" android:icon="@drawable/icon" android:label="@string/app_name" android:enabled="true"/>

如果你的不起作用,试试这样做:

<service android:name="com.my.qualified.MyIntentService" android:icon="@drawable/icon" android:label="@string/app_name" android:enabled="true"/>

编辑

当你进入 设置 >> 应用程序 >> 运行服务 页面时,会显示正在运行的服务列表。

android:icon将是缩略图图像

androin:label 将是显示文本


声明一个图标有什么作用?启用标签又是什么意思? - gtdevel
请在此处查看解释:http://developer.android.com/guide/topics/manifest/service-element.html - hooked82

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接