How to remove an alarm when a user deletes an event?

I am adding an event to my schedule list and the alarm has been fixed for this event. I have to repeat the alarm for every minute, starting at the five minute end of the event. Below are the conditions that I must remove or cancel the alarm for a specific event.

  • When I delete an event from my schedule.
  • The event is scheduled, but I do not want an alarm for the event.

I follow concepts like sqlite database, Alarm manger, Services. I am a little confused using Services and pendingIntent. So please offer me the right way to fit my requirement.

+6
source share
1 answer

You need to use the cancel(...) method from AlarmManager , using the same PendingIntent that you used to set the alarm. Example:

 this.getAlarmManager().cancel(mAlarmPendingIntent); 

( this refers to an Activity or Service from which you cancel the alarm).

Here is the link for the API .

Create a PendingIntent as:

 mAlarmPendingIntent = PendingIntent.getActivity(this, requestCode, intent, flags); 

The doc API for PendingIntent is here .

+7
source

Source: https://habr.com/ru/post/890024/


All Articles