小臭蛋儿
小臭蛋儿

Reputation: 43

AlarmManager timer

When useing AlarmManager ,i set many timers,each timer for different broadcast receiver, and they will auto merge or not?

    Intent intent = new Intent(TimeModeService.this,TimeModeReceiver.class);
    intent.setAction("startTimeMode");
    PendingIntent startIntent = PendingIntent.getBroadcast(getApplicationContext(),1000, intent,0);
    can.set(Calendar.HOUR_OF_DAY, startHour);
    can.set(Calendar.MINUTE,startMin);
    alarmmanager.setRepeating(AlarmManager.RTC_WAKEUP, can.getTimeInMillis(), (24 * 60 * 60 * 1000), startIntent);

Upvotes: 1

Views: 869

Answers (1)

SpeedBirdNine
SpeedBirdNine

Reputation: 4676

In, PendingIntent.getBroadcast(getApplicationContext(),1000 /*this is requestCode*/, intent,0); If you keep the requestCode same for different instances of PendingIntent, and then set alarm using them, they should merge, in android 2.3.3, if i keep it same (for starting an activity) only one activity started. Here i would mention that alarmManager.set was used not alarmManager.setRepeating.

I used int requestCode = (int)Calendar.getInstance().getTimeInMillis(); to keep the request code different for different pendingIntents.

But Official Reference mentions it as

requestCode     Private request code for the sender (currently not used).

So the best way is to try it for your situation, but different PendingIntents with same requestCode would merge.

Upvotes: 1

Related Questions