[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 ...
随机推荐
- 用Storyboard构建标签栏多页面应用程序UI
注: 貌似CSDN的显示效果不佳,假设有须要的话我能够上传pdf格式的: 另外假设文章中有错误还请给位多多提意见,谢谢. pdf格式文档:http://download.csdn.net/detail ...
- FL2440 rt3070模块station模式移植
---------------------------------------------------------------------------------------------------- ...
- 一起來玩鳥 Starling Framework(1)一定要的Hello World!
雖然已經一堆Hello World的介紹文章跟影片了,但中文資料畢竟是比較少,所以不能免俗的來一篇中文版Hello World.首先開啟一個AS3.0專案,fps不用客氣,設為60,Starling很 ...
- [Python爬虫] 之二十四:Selenium +phantomjs 利用 pyquery抓取中广互联网数据
一.介绍 本例子用Selenium +phantomjs爬取中广互联网(http://www.tvoao.com/select.html)的资讯信息,输入给定关键字抓取资讯信息. 给定关键字:数字:融 ...
- 【招聘App】—— React/Nodejs/MongoDB全栈项目:socket.io&聊天实现
前言:最近在学习Redux+react+Router+Nodejs全栈开发高级课程,这里对实践过程作个记录,方便自己和大家翻阅.最终成果github地址:https://github.com/66We ...
- PHP关闭notice级别报错信息
1.在php.ini文件中改动error_reporting改为:error_reporting=E_ALL & ~E_NOTICE2.如果你不能操作php.ini文件,你可以使用如下方法在你 ...
- 子系统设计和FishiGUI的子系统设计
目的和问题: 除了依赖关系.还要规范操作系统适配层的全部接口.仅仅要操作系统适配层的接口在移植过程中始终保持稳定.框架层的设计和实现就不会收到影响.可是为了实现同一接口的目标,为了保证相同的功能接口能 ...
- HTML5 Canvas 绘制库存变化折线
<!DOCTYPE html> <html lang="utf-8"> <meta http-equiv="Content-Type&quo ...
- 用C++实现文件压缩(1 哈弗曼编码)
今天下午想把文件压缩写一下,因为我觉得这个还是比较锻炼技术的,对数据结构的要求应该比较高,权当练习了吧. 我采用的压缩方式是Huffman编码,不过比较囧的是,我拼写拼错了,我拼的是haffman,在 ...
- hibernate学习系列-----(9)hibernate对集合属性的操作之Map集合篇
照旧,先新建一个StudentMap.java实体类,将hobby属性使用map集合接口来存放: package com.joe.entity; import java.util.Map; publi ...