Cancel alarm using the Alarmmanager.cancel () function, the incoming parameter is a pendingintent instance.
This function will all pendingintent the same alarm all cancel, how to determine whether the two are the same, Android uses Intent.filterequals (), specifically to determine the two pendingintent action, The data, type, class, and category are identical.
The specific code is as follows:
To set an alarm:
//specifying the start alarmactivity componentIntent Intent =NewIntent (alarmtest. This, alarmactivity.class); Intent.setaction ("111111"); //Create a Pendingintent objectPendingintent pi =pendingintent.getactivity (alarmtest. This,0, Intent,0); Calendar C=calendar.getinstance (); //set Calendar object based on user selection timeSystem. out. println ("Hourofday ="+hourofday); System. out. println ("minute ="+minute); C.Set(Calendar.hour, hourofday); C.Set(Calendar.minute, MINUTE); //set Alarmmanager to start the specified component at the time of the calendarAmanager.Set(Alarmmanager.rtc_wakeup, C.gettimeinmillis (), pi);
To cancel the alarm:
// used to cancel the New Intent (alarmtest. this, alarmactivity. class ); Intent.setaction ("111111"); // Create a Pendingintent object Pendingintent pendingintent = pendingintent.getactivity ( alarmtest. This, 0, intent, 0); Amanager.cancel (pendingintent);