Bringing down service while still waiting for start foreground
开发中遇到问题:不能在后台启动service
解决办法:
1.启动服务做判断
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {//android8.0以上通过startForegroundService启动servicestartForegroundService(intent);
} else {startService(intent);
}
2.在service中修改通知设置
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder builder;
int channelId = 1;
NotificationChannel channel = new NotificationChannel(String.valueOf(channelId), "name", NotificationManager.IMPORTANCE_NONE);
manager.createNotificationChannel(channel);
builder = new NotificationCompat.Builder(this, String.valueOf(channelId));
Notification notification = builder.build();
startForeground(channelId, notification);
我看网上还有一种方法是将app设置为系统应用。
作为系统应用,是有权限后台启动service的,所以加上android:sharedUserId="android.uid.system"获取系统权限,设置为系统级进程,再对apk进行系统签名。
不过这个方法我没有验证,记录一下。
Bringing down service while still waiting for start foreground相关推荐
- ANR系列之五:Service类型ANR原理讲解
前言: ANR系列文章一共有有若干篇, 遵循这样的一个顺序依次讲解: 1.先讲ANR的基本概念以及ANR发生后的流程: 2.四种类型的ANR是如何发生的: 3.该如何排查和解决ANR类型问题. 想看整 ...
- Android的服务(Service)(一)生命周期
本篇和接下来的几篇我们来浅析一下Android的另外一个非常重要的组件:Service,看到这里我们的脑海里都会涌现出什么词语呢?诸如:无用户交互界面,耗时后台操作,服务(级别)进程,远程调用. 1. ...
- Android 源码分析(三) Service 启动分析
//android-8.0.0_r1\frameworks\base\core\java\android\content\Context.java/** * startService是Context的 ...
- service启动流程
调用startservice()进入ContextWrapper类的startService方法 这里mBase是一个Context,即调用Context类的startservice(),而conte ...
- (七十)Android O Service启动流程梳理——bindService
前言:最近在处理anr问题的时候迫切需要搞清楚service的启动流程,抽时间梳理一下. 1.service启动简述 service启动分三种,比较简单的就是startService,Android ...
- Spawn service failed. Exiting. 的处理方法
问题内容: [INFO] [1645350157.294176, 1638263152.727635]: Spawn status: SpawnModel: Entity pushed to spaw ...
- 深入理解Binder机制4-bindService过程分析
一.概述 1.1 Binder架构 Android内核基于Linux系统,而Linux系统进程间通信方式有很多,如管道,共g享内存,信号,信号量,消息队列,套接字.而Android为什么要用binde ...
- Android10.0 startService启动过程
原文地址:https://skytoby.github.io/2019/startService%E5%90%AF%E5%8A%A8%E8%BF%87%E7%A8%8B/ 基于Android10.0, ...
- 灾难恢复_有效的灾难恢复计划的10个技巧
灾难恢复 For many companies, reliance on IT means that they would not be able to operate if their system ...
最新文章
- ebay OA题目汇总 (更新于20210728)
- 2021-03-15 深入理解SLAM技术【1】 基础知识
- 【若依(ruoyi)】自定义的数据选择对话框
- kafka如何彻底删除topic及数据
- Android之Caused by: java.lang.IllegalArgumentException: Failed to find configured root that contains
- Analyzing Storage Performance using the Windows Performance Analysis ToolKit (WPT)
- 【Python3网络爬虫开发实战】 1.2.2-Selenium的安装
- java完整分页算法,最简单的java分页算法
- IE 代理服务器设置程序实现
- “鹏城”伴你鹏程:下届全国人工智能大赛再会!
- 结构体初始化为0的技巧!!
- 工地信息化——施工现场网格化管理系统实施小记
- AD软件出现“Your license is already used on computer “LAPTOP-F99R6OR1“ using product “AltiumDesigner“
- 徐志摩《翡冷翠的一夜》
- 人工智能于交通系统而言
- 一个成功的男人如何去追求身边的女人
- FNDLOAD命令整合
- 浮云API免费开放接口
- php 输出gif 不动,PS制做的gif动画导出后动图不动了怎么办?
- Python mariadb