如何正确地将独特的附加功能传递给待处理的意图?

编程入门 行业动态 更新时间:2024-10-26 10:29:25
本文介绍了如何正确地将独特的附加功能传递给待处理的意图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在使用 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:

  • android 待处理 Intent 通知问题
  • Android 不断缓存我的 Intent 额外内容,如何声明一个挂起的 Intent 以保留新的额外内容?

我已经尝试过:

  • 为每个待处理的意图分配一个唯一的 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").

更多推荐

如何正确地将独特的附加功能传递给待处理的意图?

本文发布于:2023-11-27 04:39:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636628.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:意图   正确地   独特   功能

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!