首页 > 学院 > 开发设计 > 正文

Service Intent must be explicit

2019-11-08 00:31:53
字体:
来源:转载
供稿:网友

java.lang.IllegalArgumentException: Service Intent must be explicit: Intent

在Activity中启动Service的时候报错: 服务意图必须是显性声明。 这是为了防止造成冲突(有多个Service用同样的intent-filter的情况)

这是Android 5.0 (Lollipop) 之后的规定。 不能用包名的方式定义Service Intent, 而要用显性声明:

new Intent(Context, Service.class);

Intent intent = new Intent();intent.setAction("com.itheima74.remoteservice");mConn = new MyConn();bindService(intent,mConn,BIND_AUTO_CREATE);
remoteservice 类在清单文件配置了action,4.1手机能正常运行,7.1不行


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表