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如何比较待处理的意图
发布评论