Search code examples
androidalarmmanageralarm

Delete Alarm with a unique ID


I do have a NoteApp, where you can set reminder.

I want to implement that you can cancel the alarm.

My problem is I cant find any tutorial how to do this.

I've set an unique ID and saved it into the SQLite Database.

So when I click on Dialog "Yes" it should cancel the Alarm.

Here I set the alarm:

Intent i = new Intent(NeueNotiz.this,NoteNotification.class);

PendingIntent pendingIntent = PendingIntent.getBroadcast(NeueNotiz.this, (int) System.currentTimeMillis(),i,0);

AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);

                                isAlarmSet(true,String.valueOf(cal_new.getTimeInMillis()));

                                alarmManager.setExact(AlarmManager.RTC_WAKEUP,cal_new.getTimeInMillis(),pendingIntent);

I have absolutely no clue.
Help please


Solution

  • AlarmManager alarmManager = (AlarmManager) 
    getSystemService(Context.ALARM_SERVICE);
     Intent myIntent = new Intent(getApplicationContext(),
        SessionReceiver.class);
     PendingIntent pendingIntent = PendingIntent.getBroadcast(
                getApplicationContext(), 1, myIntent, 0);
    
     alarmManager.cancel(pendingIntent);
    

    See How to cancel alarm from AlarmManager link for more info.