[Android L]关于Android L的Service启动问题
一 问题描写叙述
Android L[Android5.X.X] 版本号通过Intent隐式启动service时将会报出下面错误:
AndroidRuntime( 792):
java.lang.IllegalArgumentException: Service Intent must be explicit
【声明】欢迎转载,但请保留文章原始出处:http://blog.csdn.net/yelangjueqi/article/details/46754581
具体信息:
01-02 07:52:44.736 D/PowerManagerService/SmartStandby( 792): sendDetectFaceIntent:com.wtk.smart.standby.DETECT_FACE_ACTION
01-02 07:52:44.738 W/ContextImpl( 792): Calling a method in the system process without a qualified user: android.app.ContextImpl.startService:1813 com.android.server.power.PowerManagerService.sendDetectFaceIntent:4155 com.android.server.power.PowerManagerService.handleDetectFaceCase:4137
com.android.server.power.PowerManagerService.access$4400:100 com.android.server.power.PowerManagerService$PowerManagerHandler.handleMessage:3306
01-02 07:52:44.744 E/AndroidRuntime( 792): *** FATAL EXCEPTION IN SYSTEM PROCESS: PowerManagerService
01-02 07:52:44.744 E/AndroidRuntime( 792): java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.wtk.smart.standby.DETECT_FACE_ACTION (has extras) }
01-02 07:52:44.744 E/AndroidRuntime( 792): at android.app.ContextImpl.validateServiceIntent(ContextImpl.java:1801)
01-02 07:52:44.744 E/AndroidRuntime( 792): at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1830)
01-02 07:52:44.744 E/AndroidRuntime( 792): at android.app.ContextImpl.startService(ContextImpl.java:1814)
01-02 07:52:44.744 E/AndroidRuntime( 792): at com.android.server.power.PowerManagerService.sendDetectFaceIntent(PowerManagerService.java:4155)
01-02 07:52:44.744 E/AndroidRuntime( 792): at com.android.server.power.PowerManagerService.handleDetectFaceCase(PowerManagerService.java:4137)
01-02 07:52:44.744 E/AndroidRuntime( 792): at com.android.server.power.PowerManagerService.access$4400(PowerManagerService.java:100)
01-02 07:52:44.744 E/AndroidRuntime( 792): at com.android.server.power.PowerManagerService$PowerManagerHandler.handleMessage(PowerManagerService.java:3306)
01-02 07:52:44.744 E/AndroidRuntime( 792): at android.os.Handler.dispatchMessage(Handler.java:111)
01-02 07:52:44.744 E/AndroidRuntime( 792): at android.os.Looper.loop(Looper.java:194)
01-02 07:52:44.744 E/AndroidRuntime( 792): at android.os.HandlerThread.run(HandlerThread.java:61)
01-02 07:52:44.744 E/AndroidRuntime( 792): at com.android.server.ServiceThread.run(ServiceThread.java:46)
01-02 07:52:44.752 V/SettingsProvider( 792): call(global:dropbox:system_server_crash) for 0
01-02 07:52:44.753 D/SettingsProvider( 792): lookupValue table global cache.fullyMatchesDisk() dropbox:system_server_crash
01-02 07:52:44.757 V/SettingsProvider( 792): call(global:logcat_for_system_server_crash) for 0
01-02 07:52:44.757 D/SettingsProvider( 792): lookupValue table global cache.fullyMatchesDisk() logcat_for_system_server_crash
二 问题分析
A . 定位问题点
sdk\sources\android-21\android\app\ContextImpl.java
class ContextImpl extends Context {
......
private void validateServiceIntent(Intent service) {
if (service.getComponent() == null && service.getPackage() == null) {
if (getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.LOLLIPOP) {
IllegalArgumentException ex = new IllegalArgumentException(
"Service Intent must be explicit: " + service);
throw ex;
} else {
Log.w(TAG, "Implicit intents with startService are not safe: " + service
+ " " + Debug.getCallers(2, 3));
}
}
}
......
}
B .分析过程
上面源代码中蓝色加粗部分:service.getComponent() == null && service.getPackage() == null
表明通过intent启动service时, 须要指定Intent的ComponentName信息:intent.setComponent(xxx),或指定Intent的setPackage("包名"),假设两者都没有指定的话将会报以上错误。尤其在framework层启动APP层的service时。假设是隐式启动service,可能会导致系统进程挂掉。出现不断重新启动的现象。
三 解决方法
參考一
Intent intent = new Intent();
ComponentName componentName = new ComponentName(pkgName,serviceName);
intent.setComponent(componentName);
context.startService(intent);
參考二
Intent mIntent = new Intent();
mIntent.setAction("XXX.XXX.XXX");//Service可以匹配的Action
mIntent.setPackage(pkgName);//应用的包名
context.startService(mIntent);
四 延伸官网
The Context.bindService() method now requires an explicit Intent, and throws an exception if given an implicit intent. To ensure your app is secure, use an explicit intent when starting or binding your Service, and do not declare intent filters for the service.
也就是说。在5.0以后不同意使用隐式Intent方式来启动Service
[Android L]关于Android L的Service启动问题的更多相关文章
- android中service启动后台程序
Service是Android中一个类,它是Android四大组件之一,使用Service可以在后台执行长时间的操作( perform long-running operations in the b ...
- 转Android service 启动篇之 startForegroundService
本文转自:https://blog.csdn.net/shift_wwx/article/details/82496447 前言: 在官方文档 Android 8.0 行为变更 中有这样一段话: An ...
- Android Service 启动和停止服务
activity_main.xml 定义两个Button控件,start_service和stop_service. <LinearLayout xmlns:android="http ...
- Android 四大组件之再论service
service常见的有2种方式,本地service以及remote service. 这2种的生命周期,同activity的通信方式等,都不相同. 关于这2种service如何使用,这里不做介绍,只是 ...
- Android 综合揭秘 —— 全面剖释 Service 服务
引言 Service 服务是 Android 系统最常用的四大部件之一,Android 支持 Service 服务的原因主要目的有两个,一是简化后台任务的实现,二是实现在同一台设备当中跨进程的远程信息 ...
- Android组件系列----Android Service组件深入解析
[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/4 ...
- Android基调(十六)- Service:startService()、stopService()、bindService()、unbindService()加
直行 第一 另外一种 第三种 总结 开门见山 开启服务有三种情况:假设直接使用服务,则没有必要进行绑定,可是假设要使用服务里面的方法.则要进行绑定. 具体的启动情况有下: ①调用startServic ...
- Android Binder分析二:Natvie Service的注冊
这一章我们通过MediaPlayerService的注冊来说明怎样在Native层通过binder向ServiceManager注冊一个service,以及client怎样通过binder向Servi ...
- Android中startService的使用及Service生命周期
Android中有两种主要方式使用Service,通过调用Context的startService方法或调用Context的bindService方法.本文仅仅探讨纯startService的使用.不 ...
- Android 7.1.1 锁屏界面启动流程
前几天遇到一个低概率复现锁屏界面不显示,仅仅显示状态栏的问题,跟了下锁屏界面启动显示的流程,在这分享下,也方便以后自己查看.前面简介了下Zygote启动流程, Zygote进程启动后会首先创建一个Sy ...
随机推荐
- sqlmapapi的跨域访问Access-Control-Allow-Origin:*;ajax
1.做sqlmapapi的二次开发时,需要通过ajax方式调用sqlmapapi,但是默认情况下,sqlmapapi是不允许跨域访问的 2.尝试增加ajax的header,修改origin的值,来避免 ...
- ubuntu16.04 登录密码破解方法
1:开机按Shift键,出现如下界面.(手速要快,Shift键要按时间久一点) 选择第二项 2:按回车键进入如下界面,然后选中有recovery mode的选项(第三项) 3:按e进入如下界面,并找到 ...
- 初识FASTBuild 一个大幅提升C/C++项目编译速度的分布式编译工具
FASTBuild 是一款高性能.开源的构建系统,支持高度可扩展的编译,缓存和网络分发. 以上是FASTBuild官网对其产品的一句话介绍. FASTBuild 的开源地址:https://githu ...
- mac重置蓝牙模块
升级系统后蓝牙鼠标无法连接,蓝牙模块也无法关闭,通过重置 PRAM和SMC解决 PRAM 重置 关机,拔掉所有外设,接上电源. 启动时同时按住 Command, Option, p, r , 听到三次 ...
- 输入N,打印如图所看到的的三角形(例:N=3,N=4,N=5)1<=N<=26
package demo; public class PrintDemo { public static void main(String[] args) { print(26); } private ...
- 别样JAVA学习(六)继承下(2.3)异常下
1.RuntimeException Exception中有一个特殊的子类异常RuntimeException执行时异常. 假设在函数内容抛出该异常,函数上能够不用声明.编译一样通过. 假设在函数上声 ...
- 普通用户 crontab 任务不运行
今天发如今linux下,普通用户的crontab任务不运行.网上搜了好多.好多说要在运行的脚本前面加上例如以下内容 if [ -f ~/.bash_profile ]; then . ~/.bas ...
- Linux /proc/pid目录下文件的含义 (转)
2013-01-16 16:10:36 分类: LINUX attr: 进程的属性 cmdline: 启动进程时执行的命令 cwd: 指向进程当前工作目录的软链 environ: 进程执行时使用的环境 ...
- loadrunner脚本中写入脚本输出log到外部文件,分析参数取值方式
loadrunner脚本中写入脚本输出log到外部文件,分析参数取值方式 分类: 心得 loadrunner 我的测试 2012-04-01 12:52 2340人阅读 评论(0) 收藏 举报 脚本l ...
- <转>c++ builder JSONCPP 注意事项 XE2 解决编译问题 _Mfl
在C++Builder中使用JSONCPP需要注意的问题 1.使用STL的MAP而不是内建的MAP这个问题实际上和编译器无关.内建的MAP不是很稳定,当解析数据大于600K左右时,会崩溃.虽然一般来说 ...