我是靠谱客的博主 包容水池,这篇文章主要介绍Caused by: java.lang.IllegalStateException: Not allowed to start service Intent,现在分享给大家,希望可以做个参考。
Caused by: java.lang.IllegalStateException: Not allowed to start service Intent { cmp=package/xxx.xxxService }: app is in background uid UidRecord
Android 8.0(+)不允许在后台启动/创建Service,直接调用context.startService(intent)会宕机。
临时解决办法:
将编译版本和目标版本降级到25,就可以避免因为8.0(26)不允许APP在后台启动Service而宕机。因为系统版本向后兼容。
根本解决办法:
1、SDK26 启动Service的方法:context.startForegroundService(context, Service.class);
2、SDK26 Service启动时,即在onCreate方法中,context.startForeground(id, new Notification());
2、SDK26 Service启动时,即在onCreate方法中,context.startForeground(id, new Notification());
最后
以上就是包容水池最近收集整理的关于Caused by: java.lang.IllegalStateException: Not allowed to start service Intent的全部内容,更多相关Caused内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复