Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I remove alarm when user delete event?

I am adding an event to my schedule list and alarm has been fixed to that event. I have to repeat alarm for every one minute, from the before five minutes of event ending time. In below conditions I have to remove or cancel alarm for particular event.

  1. When I delete event from my schedule.
  2. Event placed in schedules but I don't want alarm for event.

I am following concepts like sqlite database, Alarm manger, Services. I am confusing little bit using Services and pendingIntent. So, please suggest me the right way to approach my requirement.

like image 705
SBK Avatar asked Jun 08 '11 05:06

SBK


1 Answers

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

this.getAlarmManager().cancel(mAlarmPendingIntent);

(this refers to the Activity or the Service from which you are cancelling the alarm).

Here is the link for the API.

Create the PendingIntent as:

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

The API doc for PendingIntent is here.

like image 94
Aleadam Avatar answered Oct 08 '22 00:10

Aleadam