当前位置: 首页 > 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.lryc.cn/news/607201.html

相关文章:

  • C++ --- stack和queue的使用以及简单实现
  • 【AI问答】PromQL中interval和rate_interval的区别以及Grafana面板的配置建议
  • UE5 动态扫描波
  • python入门第一天---变量+数据类型及注释的使用
  • SpringAI智能客服Function Calling兼容性问题解决方案
  • LRU缓存淘汰算法的详细介绍与具体实现
  • 简单打包应用
  • pve 删除集群
  • AI+向量化
  • 超算中尝试安装dify(失败)
  • Windows编译安装ffmpeg和sdl
  • 电子电气架构 --- 软件项目变更管理
  • Squid服务配置代理
  • 荣耀平板儿童限制
  • 温度影响的材料合成与生长-属于动力学控制还是热力学控制
  • 美团进军折扣超市,外卖未平、超市大战再起?
  • 什么是三防平板电脑?三防平板有什么作用?
  • Qt-----初识
  • Cesium性能优化
  • android MVC/MVP/MVVM/MVI架构发展历程和编写范式
  • W3D引擎游戏开发----从入门到精通【10】
  • 蚂蚁开源团队发布的2025大模型开源开发生态发展情况速览
  • androidstudio调试apt
  • Ubuntu 系统下使用 lsusb 命令识别 USB 设备及端口类型详解
  • LS-DYNA 分析任务耗时长,企业如何科学提升许可证使用效率?
  • Flask 中的应用上下文和请求上下文
  • [AI8051U入门第十二步]W5500-Modbus TCP从机
  • SQLFlash:一款由AI驱动的SQL优化工具
  • leetcode热题——全排列
  • 《平台经济法律风险合规发展》研讨会在北京召开