Android-Service Intent must be explicit异常说明

野性酷女 2022-06-08 00:59 245阅读 0赞

在Android 5.0采用隐式意图启动方式

  1. Intent intent = new Intent();
  2. intent.setAction("com.jeiker.myapp.MyService1");
  3. bindService(intent, conn, BIND_AUTO_CREATE);

会出现Service Intent must be explicit异常报错。

解决方案:

从Lollipop开始,service服务必须采用显式意图方式启动.

  1. Intent intent = new Intent();
  2. intent.setAction("com.jeiker.myapp.MyService1");
  3. //指定启动的是那个应用(com.jeiker.myapp)中的Action(com.jeiker.myapp.MyService1)指向的服务组件
  4. intent.setPackage("com.jeiker.myapp");
  5. bindService(intent, conn, BIND_AUTO_CREATE);

发表评论

表情:
评论列表 (有 0 条评论,245人围观)

还没有评论,来说两句吧...

相关阅读