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

PendingIntent的flag和原理解析

flag

含义

PendingIntent.FLAG_CANCEL_CURRENT

如果PendingIntent已经存在,则取消当前的PendingIntent,重新创建一个新的PendingIntent。

PendingIntent.FLAG_NO_CREATE

如果PendingIntent已经存在,则返回null,而不是重新创建一个新的PendingIntent。

PendingIntent.FLAG_ONE_SHOT

只能使用一次,使用后会自动取消。

PendingIntent.FLAG_UPDATE_CURRENT

如果PendingIntent已经存在,则更新当前的PendingIntent。

PendingIntent.FLAG_IMMUTABLE

表示创建的PendingIntent应该是不可变的???

PendingIntent.FLAG_MUTABLE

表示创建的PendingIntent应该是可变的???

PendingIntentController的getIntentSender方法中

final boolean noCreate = (flags & PendingIntent.FLAG_NO_CREATE) != 0;
final boolean cancelCurrent = (flags & PendingIntent.FLAG_CANCEL_CURRENT) != 0;
final boolean updateCurrent = (flags & PendingIntent.FLAG_UPDATE_CURRENT) != 0;
flags &= ~(PendingIntent.FLAG_NO_CREATE | PendingIntent.FLAG_CANCEL_CURRENT| PendingIntent.FLAG_UPDATE_CURRENT);PendingIntentRecord.Key key = new PendingIntentRecord.Key(type, packageName, featureId,token, resultWho, requestCode, intents, resolvedTypes, flags,new SafeActivityOptions(opts), userId);
WeakReference<PendingIntentRecord> ref;
ref = mIntentSenderRecords.get(key);
PendingIntentRecord rec = ref != null ? ref.get() : null;
if (rec != null) {if (!cancelCurrent) {if (updateCurrent) {// FLAG_UPDATE_CURRENT标签,则更新当前的pendingIntentif (rec.key.requestIntent != null) {rec.key.requestIntent.replaceExtras(intents != null ?intents[intents.length - 1] : null);}if (intents != null) {intents[intents.length - 1] = rec.key.requestIntent;rec.key.allIntents = intents;rec.key.allResolvedTypes = resolvedTypes;} else {rec.key.allIntents = null;rec.key.allResolvedTypes = null;}}return rec;}// FLAG_CANCEL_CURRENT则先把当前的cancel掉,再重新创建一个pendingIntentmakeIntentSenderCanceled(rec, CANCEL_REASON_SUPERSEDED);mIntentSenderRecords.remove(key);decrementUidStatLocked(rec);
}
if (noCreate) {// FLAG_NO_CREATE 则直接返回当前的pendingIntentreturn rec;
}
// 重新创建一个新的
rec = new PendingIntentRecord(this, key, callingUid);

在PendingIntentRecord的sendInner中

if ((key.flags & PendingIntent.FLAG_ONE_SHOT) != 0) {// 如果是PendingIntent.FLAG_ONE_SHOT,则发送完就立刻cancel掉controller.cancelIntentSender(this, true, CANCEL_REASON_ONE_SHOT_SENT);
}

http://www.lryc.cn/news/606788.html

相关文章:

  • 如何使用淘宝开放平台API获取商品详细信息?
  • Docker设置容器时间
  • 通过pendingIntent启动activity被block问题
  • 网站QPS多少才算高并发
  • TOGAF指南1
  • Effective C++ 条款16: 成对使用new和delete时要采用相同形式
  • pycharm快捷键设置为和vscode一样
  • 数据仓库、数据湖与湖仓一体技术笔记
  • 高防服务器租用:保障数据安全
  • 自建rustdesk服务器过程记录
  • 【代码】印章提取红色部分
  • 观测云基于 ToB/ToC 业务可观测最佳实践
  • Android ConstraintLayout 使用详解
  • A 常见图形API和图形渲染引擎介绍
  • k8s云原生rook-ceph pvc快照与恢复(上)
  • 提问总结1
  • 3. boost::asio之同步读写的客户端和服务器示例
  • Syzkaller实战教程5: 初始种子加载机制剖析第一集
  • “数据管理” 一场高风险的游戏
  • CSS Text(文本)详解
  • 【工具变量】上市公司企业突破性创新及渐进性创新数据集-含处理带代码(2012-2024年)
  • Shell脚本批量检测IP的443端口联通性
  • DB-GPT 0.7.3 版本更新:支持Qwen3 Embedding和Reranker模型、支持知识库自定义检索策略等
  • 从0开始学习R语言--Day64--决策树回归
  • 登录校验一
  • zabbix平台无法删除已停用主机的处理案例
  • 【华为机试】127. 单词接龙
  • Spring Boot + MongoDB:从零开始手动配置 MongoConfig 实战
  • SAM2 : Segment Anything in Images and Videos
  • 神经网络的基础