我怎样才能正确地传递独特的群众演员挂起意图是什么?意图、正确地、挂起、群众演员

2023-09-12 23:39:41 作者:囚心锁

我在使用 alarmManager 的问题和悬而未决的意图与群众演员,将与它一起去。

如果我设置多个闹钟,他们将熄灭,但群众演员保持不变。

我已经读到这些问题:

安卓悬而未决的意图通知问题 Android的不断缓存我的意图附加功能,如何声明挂起的意图,保持新鲜的演员?

和我曾尝试:

分配一个唯一的ID给每个挂起的意图和 使用所有悬而未决的意图标志,

都无济于事。我不知道为什么它不会工作。

特殊时期,困难群众能得到哪些救助和帮扶

下面是一个code片断:

 意向意图=新的意图(CON,
                    AppointmentNotificationReciever.class);
            intent.putExtra(富,bar.toString());


            INT ID = randomNum;

            PendingIntent发送= PendingIntent.getBroadcast(CON,ID,
                    意图,PendingIntent.FLAG_UPDATE_CURRENT);


            AlarmManager AM =(AlarmManager)con.getSystemService(Context.ALARM_SERVICE);
            am.set(AlarmManager.RTC_WAKEUP,scheduleExecution,发送者);
 

解决方案

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

1),如果您已经创建了PendingIntent之前,它匹配现有的PendingIntent,那么您必须指定PendingIntent.FLAG_UPDATE_CURRENT标志,否则将无法通过临时演员。 匹配是基于Intent.filterEquals()使用,所以肯定阅读文档存在,并确保您了解数据,行动,类型等标准。

2)我读过,如果你不你的意图设置一个动作,那么它不会传播的演员,所以也许尝试intent.setAction(com.blah.Action)。

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:

android pending intent notification problem Android keeps caching my intents Extras, how to declare a pending intent that keeps fresh extras?

and I have tried:

assigning a unique ID to each pending intent and using all the pending intent flags,

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

Here is a code snippet:

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) 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) 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").