I use an Alarm to fetch data from server. I like to give user the option to start and stop the alarm. This means I have to check and see if alarm is already set. I found som
When canceling the AlarmManager
do not use a PendingIntent
with a flag of FLAG_CANCEL_CURRENT
.
Instead, cancel the PendingIntent
explicitly after canceling the alarm:
am = (AlarmManager) getSystemService(getApplicationContext().ALARM_SERVICE);
Intent i = new Intent(getApplicationContext(),AlarmReceiver.class);
PendingIntent p = PendingIntent.getBroadcast(getApplicationContext(), 0, i, 0);
am.cancel(p);
p.cancel();