Cancellation of Android Alarmmanager

Source: Internet
Author: User

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);

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.