Only one alarm fired when multiple ones are set

My goal is to fire an alarm for every event from eventsDb.getFavouriteEvents() but only one is fired everytime.

In my opinion, it may be caused by setting PendingIntent.FLAG_UPDATE_CURRENT, however I need this flag to post Extras with an intent. Is there any way not to set this flag and still post Extras with the intent?

I'm storing PendinIntents in a Collection (pendingIntents) because I'm canceling them in onDestroy() of this Service class.

This is code from 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);
}

Thanks for help!

Answers


The PendingIntent will be overwritten on send if they share the same code. Changing the code for each intent on send should correct this problem.


Need Your Help

Importing “google/protobuf/descriptor.proto” in java protocol buffers

java protocol-buffers

I have a .proto file definition which needs to import "google/protobuf/descriptor.proto" because I use Custom Options.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.