一 问题描述

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);

四 延伸官网

Binding to a Service
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启动问题相关推荐

  1. 一篇文章看明白 Android Service 启动过程

    Android - Service 启动过程 相关系列 一篇文章看明白 Android 系统启动时都干了什么 一篇文章了解相见恨晚的 Android Binder 进程间通讯机制 一篇文章看明白 An ...

  2. Android service 启动篇之 startService

    系列博文: Android 中service 详解 Android service 启动篇之 startService Android service 启动篇之 bindService Android ...

  3. 最新android 电脑系统,android l操作系统|android l操作系统最新版 - 系统天堂

    Android新一代操作系统被称为"L",采用被称为"材料设计"的全新设计语言,这是谷歌为了解决碎片化问题的重要举措,将统一包括手机. 平板.笔记本以及网页端设 ...

  4. service启动activity_「 Android 10 四大组件 」系列—Service 的 quot; 启动流程 quot;

    作者:DeepCoder 核心源码 关键类路径 Service 的启动过程相对 Activity 的启动过程来说简单了很多,我们都知道怎么去创建和启动一个 Service, 那么你有没有从源码角度研究 ...

  5. android ripple 大小,Android L限制Ripple水波纹范围大小

    Android L限制Ripple水波纹范围大小 Ripple 简介 Android 5.0 之后 google 推出了 Material Design,Botton 默认的触摸反馈会有水波纹涟漪效果 ...

  6. android L和android M的区别

    android L与android M的区别主要还是应该关注M对L的改进.Android M相比Android Lollipop(5.0)有六项重大的改进: 1.App Permissions(软件权 ...

  7. 深入分析Android 9.0源代码——Service启动流程(startService方式)

    引言 点击此处查看<深入分析Android 9.0源代码>系列的组织结构和相关说明. 1 应用进程发起启动请求 本章的调用流程如下图所示: (Context)ContextWrapperC ...

  8. Android Service启动到Activity

    飞哥语录:心怀希望,就会充满力量! 从Service启动到Activity基本可以分为两类: 1.从自己应用的Service启动自己应用的Activity,即显式意图: 2.从自己应用的Service ...

  9. Service启动泄露异常:android.app.ServiceConnectionLeaked

    项目场景: 在子线程中启动服务 在Activity中启动服务 问题描述: 软件在运行过程中,相关服务抛出异常:android.app.ServiceConnectionLeaked 详细日志: Ser ...

  10. android l 新功能,Android L怎么样 安卓L新特性汇总

    在刚刚结束的2014谷歌IO大会上,谷歌共发布了8款新品,其中Android L成为发布会的一大看点.此次谷歌并没有将新安卓系统命名为Android 5.0,而是命名为Android L.仅从命名来看 ...

最新文章

  1. Spring Boot 2.0 常见问题总结(一)
  2. 6月份不良与垃圾信息举报:垃圾邮件占40.4%
  3. linux进程的地址空间
  4. 爬虫学习笔记(十五)——加密解密
  5. 高压线下,恶俗短视频为何仍在批量生产?
  6. 二分法分页 mysql_LeetCode 04寻找两个正序数组的中位数(困难)二分法
  7. java 反射 new class_Java高级特性-反射:不写死在代码,还怎么 new 对象?
  8. poj3190 Stall Reservations(贪心+STL)
  9. MATLAB GUI如何创建Callback函数
  10. java 抛出异常效率_Java异常处理机制
  11. 印度 语言简称_保存印度的语言和文化:图卢维基百科的诞生
  12. python写一个类_python3学习笔记--002--写一个类
  13. mssql 将查询结果作为表名参数_MySQL·查询(一)
  14. 190523每日一句
  15. Hadoop—数据仓库分层介绍
  16. win10u盘被写保护怎么解除_Win10系统下U盘写保护应该如何破除!
  17. 555集成定时器及其应用
  18. Loadrunner:管理员权限启动报错“win10为了对电脑进行保护,已经阻止此应用”
  19. 【校招VIP 前端】电影详情模块的开发文档设计实战
  20. jQuery中关于jQuery.fn.init.prototype = jQuery.fn的解读

热门文章

  1. springboot中使用@ConfigurationProperties(prefix = “xxx“) 取值为空问题
  2. 公理化体系降维打击1之补充(脱敏版本)再加俺老孙的故事(开头)
  3. halcon缺陷检测学习3暗斑检测detect_mura_defects_texture
  4. HBase的核心模块介绍
  5. 关于读懂时序图写时序
  6. 用户思维+:好产品让用户为自己尖叫
  7. MATLAB中数据相关性所求相关系数的有关内容(3)
  8. PP实施经验分享(6)——SAP生产订单计划内投料计划外投料
  9. 一个最简单的Java程序
  10. U盘突然“u盘无法访问文件或目录损坏且无法读取” 吓死宝宝了 解决方案 好使哈