0

I have the problem removing the alarm which I already set. I used two activities to "ADD" or "EDIT" alarms. When I delete an alarm, I want to use the activity which is made to show list of alarms. However, It doesn't delete the PendingIntent I set.

Here's the part of my source code in List Activity.

private void removeAlarm(int number)
{
    final int alarmCode = AlarmCodeCreator.CreateNum(1, clickedPosition, 0);

    AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(ListMainActivity.this,
            PushMainActivity.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(
            getApplicationContext(), alarmCode, intent, 0);
    alarmManager.cancel(pendingIntent);
    System.out.println(alarmCode);
}

1 Answers1

0

You should use the PendingIntent.FLAG_UPDATE_CURRENT flag and make sure to create the PendingIntent the same way it was originally created. Same answer here.

Community
  • 1
  • 1
BrainCrash
  • 12,992
  • 3
  • 32
  • 38