检测机构报告,说我们app在杀死app有自启动和关联启动行为
情况一
排查中发现一种情况是AlarmManager定时任务导致的
@kotlin.jvm.JvmStatic
fun startBDAlarmManager(context: Context, intervalInMS: Long) {
// 启动定时器,发送BD_stat
startAlarmManager(context, intervalInMS, BDTimerReceiver::class.java)
}
private fun startAlarmManager(context: Context, intervalInMS: Long, clazz: Class<*>) {
try {
val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager?
val intent = Intent(context, clazz)
val pIntent = PendingIntent.getBroadcast(context, 0, intent, 0)
// 立即启动,有些手机上延迟会收不到通知
if (alarmManager != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + intervalInMS, pIntent)
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
alarmManager.setExact(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + intervalInMS, pIntent)
} else {
alarmManager[AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + intervalInMS] = pIntent
}
}
} catch (e: Exception) {
LogUtils.e(TAG, e)
}
}
```
[Android开发笔记(一百六十)休眠模式下的定时器控制](https://cloud.tencent.com/developer/article/1385113?from=15425)
[android解决AlarmManager警报器计时不准,在手机灭屏后延迟的问题](https://blog.csdn.net/qq15577969/article/details/109560167)
### 情况二
第三方推送服务使用了JobService
[JobService的使用介绍](https://blog.csdn.net/allisonchen/article/details/79218713)