android - 设置多个警报时仅触发一个警报

标签 android flags android-pendingintent android-alarms

我的目标是为 eventsDb.getFavouriteEvents() 中的每个事件触发警报,但每次只触发一个警报。

在我看来,这可能是由于设置PendingIntent.FLAG_UPDATE_CURRENT引起的,但是我需要这个标志来有 Intent 地发布附加内容。有什么方法可以不设置此标志并仍然有意地发布附加内容吗?

我将 PendinIntents 存储在集合 (pendingIntents) 中,因为我要在此 onDestroy() 中取消它们服务类。

这是来自onCreate()的代码:

for(Event event : eventsDB.getFavouriteEvents()) {
  Intent intent = new Intent(AlarmReciever.ONCOMING_EVENT);
  intent.putExtra(Event.TITLE, event.getTitle());

  PendingIntent pendingIntent = PendingIntent.getBroadcast(EventAlarmService.this, 0, intent, 
    Intent.FLAG_GRANT_READ_URI_PERMISSION | PendingIntent.FLAG_UPDATE_CURRENT);
  alarmManager.set(AlarmManager.RTC_WAKEUP, event.getTime(), pendingIntent);

  pendingIntents.add(pendingIntent);
}

感谢您的帮助!

最佳答案

如果它们共享相同的代码,PendingIntent 将在发送时被覆盖。更改每个发送 Intent 的代码应该可以纠正此问题。

关于android - 设置多个警报时仅触发一个警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10422375/

相关文章:

android - 如何在 bintray(jcenter) 上为我的库获取命名空间路径?

math - DAA指令中的半进位/半借位标志

使用 GDB 进行调试时可能会导致问题的 GCC 选项

android - 在 Android Window 上获取 Activity 标志

android - 如何使用 android 远程输入将额外数据传递给广播接收器

android - 无法从 Android 10 上的 BroadcastReceiver 开始 Activity

android - Android AlarmManager仅工作一次

android - 在 Android 上使用访问 token 创建 Facebook session 对象

java - UDACITY Sunshine Android 应用程序显示多个数据值和多个刷新选项

android - Genymotion 无法在 Mac 上启动