-1

I have used the below code to set the alarm,

mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
                activeModeTime.getTimeInMillis(), AlarmManager.INTERVAL_DAY,
                getActiveModeAlarmPendingIntent());

Every time when my app starts in the Home screen activity I am setting the alarm again and again.

I know that all scheduled alarm will be cancelled once the device goes power off. Once the power is on all the alarms will be scheduled again.

But I don't know how to check the alarm has been scheduled already or not every time when the app start.

And also please confirm the below, Setting again again and again once the app starts will replace the old alarm and will be fired if the time passed already. How to avoid of this multiple alarm setting by check the alarm scheduled or not programmatically?

Please help me on this.

mjs
  • 2,837
  • 4
  • 28
  • 48
M Vignesh
  • 1,586
  • 2
  • 18
  • 55
  • possible duplicate of [How to check if AlarmManager already has an alarm set?](http://stackoverflow.com/questions/4556670/how-to-check-if-alarmmanager-already-has-an-alarm-set) – Psypher Feb 23 '15 at 10:42
  • @ZygoteInit You mean the place where it requires? Asking for the sample scenario. – M Vignesh Mar 16 '15 at 06:11

1 Answers1

0

Create an equivalent PendingIntent which you used with setRepeating() with PendingIntent.FLAG_NO_CREATE flag.

boolean isAlarmActive = (pendingIntent != null);
if (isAlarmActive) {
  Log.d("TAG", "Alarm is already active");
}

While using PendingIntent.FLAG_NO_CREATE, if the described PendingIntent does not already exists, it simply return null.

Hemanth
  • 2,717
  • 2
  • 21
  • 29