如何正确地将独特的附加功能传递给待处理的意图? [英] How can I correctly pass unique extras to a pending intent?

查看:23
本文介绍了如何正确地将独特的附加功能传递给待处理的意图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 alarmManager 和待处理的意图时遇到了问题,其中还有额外的内容.

I'm having a problem with alarmManager and the pending intent with extras that will go along with it.

如果我设置了多个闹钟,它们会响起,但附加功能保持不变.

If I set multiple alarms, they will go off, however the extras stay the same.

我已经阅读了这些问题:

I have already read into these questions:

我已经尝试过:

  • 为每个待处理的意图分配一个唯一的 ID 和
  • 使用所有待处理的意图标志,

一切都无济于事.我不知道为什么它不起作用.

all to no avail. I have no clue why it will not work.

这是一个代码片段:

Intent intent = new Intent(con,
                    AppointmentNotificationReciever.class);
            intent.putExtra("foo", bar.toString());


            int id = randomNum;

            PendingIntent sender = PendingIntent.getBroadcast(con, id,
                    intent, PendingIntent.FLAG_UPDATE_CURRENT);


            AlarmManager am = (AlarmManager) con.getSystemService(Context.ALARM_SERVICE);
            am.set(AlarmManager.RTC_WAKEUP, scheduleExecution, sender);

推荐答案

这里可能有两个不同的问题:

Possibly two different issues here:

1) 如果您之前已经创建了 PendingIntent 并且它匹配"了现有的 PendingIntent,那么您必须指定 PendingIntent.FLAG_UPDATE_CURRENT 标志,否则它不会传递额外内容.匹配"基于 Intent.filterEquals() 使用的标准,因此一定要阅读那里的文档并确保您了解数据、操作、类型等.

1) If you've already created your PendingIntent before and it "matches" an existing PendingIntent, then you must specify the PendingIntent.FLAG_UPDATE_CURRENT flag or it will not pass the extras. A "match" is based on the criteria that Intent.filterEquals() uses, so definitely read the docs there and make sure you understand the data, action, type, etc.

2) 我读过,如果你没有对你的意图设置一个动作,那么它就不会传播额外的东西,所以也许试试 intent.setAction("com.blah.Action").

2) I've read that if you do NOT set an action on your intent, then it will not propagate the extras, so perhaps try intent.setAction("com.blah.Action").

这篇关于如何正确地将独特的附加功能传递给待处理的意图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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