Android如何比较待处理的意图 [英] How does android compare pending intents

查看:81
本文介绍了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如何比较待处理的意图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆