0

My Code: (Alarm interval 24 hours)

Calendar calSet = Calendar.getInstance();
calSet.add(Calendar.DATE,-1);
calSet.set(Calendar.HOUR_OF_DAY, 10);
calSet.set(Calendar.MINUTE, 20);
calSet.set(Calendar.SECOND, 0);
calSet.set(Calendar.MILLISECOND, 0);

PendingIntent pi=PendingIntent.getBroadcast(context,0,i,PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);   
alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP,calSet.getTimeInMillis(),AlarmManager.INTERVAL_DAY,pi);

Lets say I'm calling this function on Jan 3rd ,11:00 As per my understanding Alarm manager has to executed twice

  1. For Jan 2nd, 10:20 (As I have added calSet.add(Calendar.DATE,-1))

  2. For Jan 3rd, 10:20 (As the current time is already 11:00)

But, the Alarm manager is triggered only once. Could someone help me with this?

I even tried

alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,calSet.getTimeInMillis(),24*60*60*1000,pi);

How can I make it to trigger twice at Jan 3rd, 11:00 (In this scenarion)

Ravindra
  • 289
  • 1
  • 4
  • 10
  • Why do you need it to run twice? – Bryan Herbst Jan 02 '15 at 19:35
  • Its a requirement of my application. Whenever the function is called, alarm should run for previous day and for current day. – Ravindra Jan 02 '15 at 19:38
  • 1
    The AlarmManager will only run once if the given date has passed, regardless of how many alarms have been "missed". You should update the logic that runs when the alarm triggers to run for both days instead of trying to get the alarm to trigger twice. – Bryan Herbst Jan 02 '15 at 19:43
  • Thanks Tanis. I updated my logic as you suggested. Alarm manager is working as I wanted it to :-) – Ravindra Jan 03 '15 at 06:15

0 Answers0