android – 无法启动服务Intent

前端之家收集整理的这篇文章主要介绍了android – 无法启动服务Intent前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我在这个问题上已经阅读了大约100个问题和答案,但我似乎无法让这个工作.我正在尝试从活动中启动服务.我的清单文件似乎没问题,我启动服务的方式似乎也是正确的. LogCat中显示以下错误

  1. ActivityManager(1296): Unable to start service Intent
  2. { cmp=com.exercise.AndroidClient/com.client.Communication }: not found

我试图通过在我的Activity中调用它来启动服务:

  1. startService(new Intent(getApplicationContext(),Communication.class));

该服务如下:

  1. public class Communication extends Service {
  2. public Communication() {
  3. super();
  4. }
  5. @Override
  6. public void onCreate() {
  7. super.onCreate();
  8. Log.i("Service","Created service");
  9. }
  10. @Override
  11. public int onStartCommand(Intent intent,int flags,int startId) {
  12. Log.i("Service","onStartCommand called");
  13. return START_STICKY;
  14. }
  15. @Override
  16. public IBinder onBind(Intent arg0) {
  17. return null;
  18. }
  19. }

我的清单文件中的条目是:

任何建议都非常适合.

最佳答案
沟通课在哪里?

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

检查包装是否正确.注意“.” (点)指的是包的根(即清单中声明的​​包).因此,例如,如果您的包是com.exercise.AndroidClient,并且您的服务类在com.exercise.AndroidClient.services.Communication下,则需要声明服务,如下所示:

或者指定完整的包:

猜你在找的Android相关文章