Multiple alarms with AlarmManager

3

How do I set more than one alarm with AlarmManager ? I recently created a topic about services , and to not couple much I decided to create another:

Look at the code I'm using:

Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 10);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);

Intent tarefaIntent = new Intent(context, ExecutarTarefaProgramadaReceiver.class);
PendingIntent tarefaPendingIntent = PendingIntent.getBroadcast(context,1234, tarefaIntent,0);

AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);

//Definir o alarme para acontecer todos os dias às 10 horas
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
                 AlarmManager.INTERVAL_DAY, tarefaPendingIntent);

It has an alarm at 10am, and an interval every 1 day, and if I want 2 alarms? ex: one of 10 and another of 11, with the same interval of 1 day?

    
asked by anonymous 27.07.2014 / 07:27

1 answer

1

You need to use different Transmission id's for pending intentions. Something like this:

 Intent intent = new Intent(load.this, AlarmReceiver.class);
final int _id = (int) System.currentTimeMillis();
PendingIntent appIntent = PendingIntent.getBroadcast(this, _id, intent,PendingIntent.FLAG_ONE_SHOT);
    
23.09.2014 / 07:41