Android如何比较待处理的意图 [英] How does android compare pending intents
问题描述
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 PendingIntent
s match, the following must be equal:
-
创建
参数PendingIntent
时使用的requestCode -
Intent
动作 - 意图
类别
-
意图
数据 -
意图
MIMETYPE -
意图
包装 -
意图
组件
- The
requestCode
parameter used when thePendingIntent
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屋!