Android如何比较待处理的意图

编程入门 行业动态 更新时间:2024-10-25 22:30:28
本文介绍了Android如何比较待处理的意图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

PendingIntent.FLAG_NO_CREATE 的文档是:

标记,表明如果所描述的PendingIntent不存在,则只需返回null而不是创建它。

Flag indicating that if the described PendingIntent does not already exist, then simply return null instead of creating it.

我的问题:使用什么标准比较PendingIntents?

我猜在此标志的内部使用 PendingIntent.equals ,但我不太确定该函数使用的标准。

I'm guessing under the hood this flag uses PendingIntent.equals, but I'm not really sure what criteria that function is using. Is it using the action, requestCode, categories, extras (I'm guessing no), etc.?

Context:

如果尚未设置我的警报,我想以挂起的意图启动警报。具体来说,我正在关注 answer 。

I want to start an alarm with a pending intent if my alarm is not already setup. Specifically, I'm following this answer.

Intent i = new Intent(applicationContext, MyService.class); i.setAction("myAction"); PendingIntent pi = PendingIntent.getService(applicationContext, /*requestCode*/0, i, PendingIntent.FLAG_NO_CREATE); if (pi != null) { AlarmManager alarmMgr = (AlarmManager)applicationContext.getSystemService(Context.AlarmService); alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, AlarmManager.INTERVAL_HOUR, AlarmManager.INTERVAL_HOUR, pi); }

推荐答案

确定是否2 PendingIntent 的匹配项,必须满足以下条件:

To determine if 2 PendingIntents match, the following must be equal:

  • 创建 PendingIntent 时使用的requestCode 参数
  • Intent 动作
  • 意图类别
  • 意图数据
  • 意图 MIMETYPE
  • 意图包装
  • 意图组件
  • The requestCode parameter used when the PendingIntent was created
  • The Intent ACTION
  • The Intent CATEGORIES
  • The Intent DATA
  • The Intent MIMETYPE
  • The Intent PACKAGE
  • The Intent COMPONENT

不考虑其他因素。

您可以在PendingIntent摘要文档和 Intent.filterEquals()。

更多推荐

Android如何比较待处理的意图

本文发布于:2023-11-09 20:20:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1573334.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:意图   Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!