Android Manifest 中如何声明 Intent 服务? [英] How is an Intent Service Declared in the Android Manifest?

查看:16
本文介绍了Android Manifest 中如何声明 Intent 服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

直截了当的问题:

Android Manifest 中是否将 IntentService 声明为常规服务,还是有其他方法?它试图寻找它,但我找不到答案.

Is an IntentService declared in the Android Manifest as a regular service, or is there another way? It tried searching for it, but I couldn't find the answer.

这是常规的服务声明:

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

谢谢

推荐答案

在您的清单中,您使用 android:name=".Communication" 声明了一个服务,这意味着您的服务类应该位于在 com.exercise.AndroidClient.Communication

In your manifest you declare a service with android:name=".Communication", this means that your service class should be located in com.exercise.AndroidClient.Communication

检查包是否正确.注意."(点)指的是你的包的根目录(即在清单中声明的​​包).因此,例如,如果您的包是 com.exercise.AndroidClient 并且您的服务类在 com.exercise.AndroidClient.services.Communication 下,则您需要声明该服务,例如这个:

Check that the packages are correct. Note that the "." (dot) refers to the root of your package (ie the package declared in the manifest). So, for example, if your package is com.exercise.AndroidClient and your service class is under com.exercise.AndroidClient.services.Communication you need to declare the service like this:

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

或指定完整包:

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

这篇关于Android Manifest 中如何声明 Intent 服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆