Caused by java.lang.IllegalStateException
Not allowed to start service Intent { cmp=com.x.x.x/.x.x.xService }: app is in background uid UidRecord{7d9f297 u0a184 SVC bg:+15m25s900ms idle change:uncached procs:3 seq(0,0,0)}
 
Android 8.0 的应用尝试在不允许其创建后台服务的情况下使用 startService() 函数,则该函数将引发一个 IllegalStateException。 新的 Context.startForegroundService() 函数将启动一个前台服务。现在,即使应用在后台运行, 系统也允许其调用 Context.startForegroundService()。不过,应用必须在创建服务后的五秒内调用该服务的 startForeground() 函数。
 

解决方法:
1. 修改启动方式

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(intent);
} else {
context.startService(intent);
}

2. 并且在service里再调用startForeground方法,不然就会出现ANR

context.startForeground(SERVICE_ID, builder.getNotification());

https://stackoverflow.com/questions/46445265/android-8-0-java-lang-illegalstateexception-not-allowed-to-start-service-inten

app is in background uid UidRecord问题原因分析

https://www.cnblogs.com/mingfeng002/p/10725364.html

Caused by java.lang.IllegalStateException Not allowed to start service Intent { cmp=com.x.x.x/.x.x.xService }: app is in background uid UidRecord(一)的更多相关文章

  1. Caused by java.lang.IllegalStateException Not allowed to start service Intent { cmp=com.x.x.x/.x.x.xService }: app is in background uid UidRecord问题原因分析(二)

    应用在适配Android 8.0以上系统时,会发现后台启动不了服务,会报出如下异常,并强退: Fatal Exception: java.lang.IllegalStateException Not ...

  2. java.lang.IllegalStateException: Not allowed to create transaction on shared EntityManager - use Spring transactions or EJB CMT instead

    java.lang.IllegalStateException: Not allowed to create transaction on sharedEntityManager - use Spri ...

  3. Caused by: java.lang.IllegalStateException: Detected both log4j-over-slf4j.jar AND slf4j-log4j12.jar on the class path, preempting StackOverflowError

    SLF4J: Detected both log4j-over-slf4j.jar AND slf4j-log4j12.jar on the class path, preempting StackO ...

  4. 【spring boot】【elasticsearch】spring boot整合elasticsearch,启动报错Caused by: java.lang.IllegalStateException: availableProcessors is already set to [8], rejecting [8

    spring boot整合elasticsearch, 启动报错: Caused by: java.lang.IllegalStateException: availableProcessors ], ...

  5. Caused by: java.lang.IllegalStateException: Method has too many Body parameters

    feign多参数问题1.1GET方式错误写法 @RequestMapping(value="/test", method=RequestMethod.GET) Model test ...

  6. Caused by:java.lang.IllegalStateException at android.media.MediaPlayer._setDataSource(Native Method)

    使用Mediaplayer播放本地音频,在第二次调用mediaplayer.setDataSource()时报错如下: Caused by: java.lang.IllegalStateExcepti ...

  7. Caused by: java.lang.IllegalStateException: Expected raw type form of org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$Match

    spring 4.0.2,mybatis 3.2.6,aspectjweaver 1.8.10 使用的时候,报错: Caused by: java.lang.IllegalStateException ...

  8. Caused by: java.lang.IllegalStateException: javax.websocket.server.ServerContainer not available

    java.lang.IllegalStateException: Failed to load ApplicationContext    at org.springframework.test.co ...

  9. Caused by: java.lang.IllegalStateException: duplicate key: datasource

    java.lang.IllegalStateException: Failed to load property source from location 'classpath:/applicatio ...

随机推荐

  1. Python基础入门-While循环

    讲完了for循环我们继续来看第二个循环,那就是while循环,while循环和for循环虽然都是循环,但是有着本质的不同.我们先来看下她们之间的区别和联系: While循环和for循环区别: 1.fo ...

  2. location.replace() keeps the history under control

    from https://dev.opera.com/articles/efficient-javascript Occasionally, it is necessary to change the ...

  3. 基于IKAnalyzer搭建分词服务

    背景 前端高亮需要分词服务,nlp团队提供的分词服务需要跨域调用,而且后台数据索引使用的IK分词.综合评价,前端分词也需要基于IK分词器. IKAnalyzer服务已经停止更新,且对Lucene支持仅 ...

  4. (转)Asp.Net生命周期系列一

    原文地址:http://www.cnblogs.com/skm-blog/archive/2013/07/07/3176713.html Asp.Net生命周期对于初级甚至中级程序员来说,一直都是一个 ...

  5. Jquery hover 事件

    hover(over,out)一个模仿悬停事件(鼠标移动到一个对象上面及移出这个对象)的方法.这是一个自定义的方法,它为频繁使用的任务提供了一种“保持在其中”的状态. 当鼠标移动到一个匹配的元素上面时 ...

  6. 《Andorid开源》greenDao 数据库orm框架

       一 前言:以前没用框架写Andorid的Sqlite的时候就是用SQLiteDatabase ,SQLiteOpenHelper ,SQL语句等一些东西,特别在写SQL语句来进行 数据库操作的时 ...

  7. C#多线程编程实战1.2暂停线程(休眠)

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...

  8. go channel缓冲区的大小

    go channel缓冲区的大小 len也可以作用于channel,代表现在channel缓冲区中还有多少数据没有读取.示例如下 c:=make(chan int,20) fmt.Println(&q ...

  9. shell和matlab之间的参数传递

        shell和matlab之间的参数传递比shell和Python之间的参数传递要简单,在matlab程序中(以.m脚本文件为例,其他程序如函数等未测试)不需要进行任何配置,直接使用即可,见下面 ...

  10. Win7下C/C++跨平台开发工具IDE的安装之CodeBlocks

    1. Win7下安装CodeBlocks: 下载带有mingw的CodeBlocks:http://www.codeblocks.org/downloads/26#windows 运行所下载程序: 点 ...