0

i Create application in android that schedule a alarm for every 20 minute. but they get canceled or not working after scheduled 5 or 8 times. is there any condition after that system cancel the scheduled alarm.

Calendar cal = Calendar.getInstance();
cal.add(Calendar.MINUTE, 20);
// Create a new PendingIntent and add it to the AlarmManager
Intent my123intent = new Intent(context, PolicyFormatDownloader.class);
my123intent.putExtra(commonGlobalVariables.IS_CALL_FROM_ALARM, true);
my123intent.putExtra(commonGlobalVariables.IS_CALL_MANUALLY, false);
PendingIntent pendingIntent = PendingIntent.getService(context, 12345,my123intent,PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); 
am.cancel(pendingIntent);
am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+ (60 * 1000 * 20), 60 * 1000 * 20,  pendingIntent);

please tell me the conditions in which alarm get cancel or clear by system. thanks for ans in advance.

MilapTank
  • 9,988
  • 7
  • 38
  • 53
Ravi Shinde
  • 17
  • 2
  • 10

1 Answers1

1

The alarm can be cleared in follwing two conditions:

  1. On device reboot All alarms set using an Alarm-Manager, are removed on device reboot

  2. If you create a Pending Intent with same ID On creation of similar PI with same ID-Value (as 12345 in this case), will overrride the previous PI.

Parth Kapoor
  • 1,494
  • 12
  • 23