当前位置: 首页 > news >正文

forceStop流程会把对应进程的pendingIntent给cancel掉

首先对比Android U和Android V的代码在forceStop时候的处理

Android U

 @GuardedBy("this")final boolean forceStopPackageLocked(String packageName, int appId,boolean callerWillRestart, boolean purgeCache, boolean doit,boolean evenPersistent, boolean uninstalling, int userId, String reasonString,int reason) {...if (packageName == null || uninstalling) {didSomething |= mPendingIntentController.removePendingIntentsForPackage(packageName, userId, appId, doit);}....return didSomething;}

Android V

@GuardedBy("this")
final boolean forceStopPackageLocked(String packageName, int appId,boolean callerWillRestart, boolean purgeCache, boolean doit,boolean evenPersistent, boolean uninstalling, boolean packageStateStopped,int userId, String reasonString, int reason) {....boolean clearPendingIntentsForStoppedApp = false;try {// stop情况下,clearPendingIntentsForStoppedApp 为trueclearPendingIntentsForStoppedApp = (packageStateStopped&& android.content.pm.Flags.stayStopped());} catch (IllegalStateException e) {// It's unlikely for a package to be force-stopped early in the boot cycle. So, if we// check for 'packageStateStopped' which should evaluate to 'false', then this should// ensure we are not accessing the flag early in the boot cycle. As an additional// safety measure, catch the exception and ignore to avoid causing a device restart.clearPendingIntentsForStoppedApp = false;}if (packageName == null || uninstalling || clearPendingIntentsForStoppedApp) {final int cancelReason;if (packageName == null) {cancelReason = PendingIntentRecord.CANCEL_REASON_USER_STOPPED;} else if (uninstalling) {cancelReason = PendingIntentRecord.CANCEL_REASON_OWNER_UNINSTALLED;} else {cancelReason = PendingIntentRecord.CANCEL_REASON_OWNER_FORCE_STOPPED;}didSomething |= mPendingIntentController.removePendingIntentsForPackage(packageName, userId, appId, doit, cancelReason);}....return didSomething;
}

可以看到Androidv相比于Androidu,多了一个 clearPendingIntentsForStoppedApp,即在应用被forceStop的时候,也会移除对应的pendingIntent

对应的堆栈调用链

并且会移除alarmManager中的PendingIntent

    private void makeIntentSenderCanceled(PendingIntentRecord rec,@CancellationReason int cancelReason) {rec.canceled = true;rec.cancelReason = cancelReason;final RemoteCallbackList<IResultReceiver> callbacks = rec.detachCancelListenersLocked();if (callbacks != null) {final Message m = PooledLambda.obtainMessage(PendingIntentController::handlePendingIntentCancelled, this, callbacks);mH.sendMessage(m);}final AlarmManagerInternal ami = LocalServices.getService(AlarmManagerInternal.class);ami.remove(new PendingIntent(rec));}

根据PendingIntent的使用场景,可能会出现以下问题:

1.脑钟应用进程再被forceStop之后,如果用户不再去打开闹钟,那么闹钟到点不会响铃

2.音乐类应用传入meidaButton中的pendingIntent失效,导致应用进程被杀之后,无法通过耳机拉起音乐进程

http://www.dtcms.com/a/309051.html

相关文章:

  • ceph 14.2.22 nautilus Balancer 数据平衡
  • 通过CISSP考试,共答到第127题
  • 雷达微多普勒特征代表运动中“事物”的运动部件。
  • 机械手弧焊电源气体流量优化方法
  • 算法:分治-快速排序
  • IO流File类的基本使用
  • 前端开发(HTML,CSS,VUE,JS)从入门到精通!第二天(CSS)
  • 《n8n基础教学》第三节:模拟一个自动化场景
  • CSS的2D转换
  • 【Shell脚本自动化编写——报警邮件,检查磁盘,web服务检测】
  • 了解Reddit自动化 社区营销更精准
  • CSS组件化样式新篇章:@scope
  • vi/vim跳转到指定行命令
  • 机器学习第二课之逻辑回归(二)LogisticRegression
  • LSTM网络从浅入深原理级讲解与Pytorch逐行讲解实现
  • [python][selenium] Web UI自动化8种页面元素定位方式
  • K8S周期性备份etcd数据实战案例
  • 番茄项目3:完成了项目的数据库设计
  • npm报错:npm install 出现“npm WARN old lockfile”
  • ZED 2/2i 相机安装与调试完整指南 | Ubuntu 20.04 + CUDA 11.8
  • k8s云原生rook-ceph pvc快照与恢复(下)
  • 前端SWR策略:优化数据请求
  • STM32学习记录--Day5
  • AG-UI 协议全面解析--下一代 AI Agent 交互框架医疗应用分析(下)
  • 接口幂等性
  • 【Flutter】双路视频播放方案
  • 《R for Data Science (2e)》免费中文翻译 (第3章) --- Data transformation(1)
  • Jupyter Notebook 使用指南
  • Idea集成Jenkins Control插件,在IDEA中触发Jenkins中项目的构建
  • 【数据可视化-78】2025年上半年广东省各市GDP排名深度解析与可视化:Python + Pyecharts 深度洞察(含完整数据、代码)