How can I cancel one AlarmManager on a scheduled time, which was already started. I am starting one AlarmManager like this.
I want to cancel it after 5 hours. How can I do this?
AlarmManager service = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, MyStartServiceReceiver.class);
PendingIntent pending = PendingIntent.getBroadcast(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);
Calendar cal = Calendar.getInstance();
cal.add(Calendar.SECOND, 30);
service.setInexactRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), REPEAT_TIME, pending);
set a another alarm for 5 hours from now. when this alarm alarm goes off then cancel the first alarm.
and, from
ReceiverForCancellingyou can cancel the first alarm.edit::