"Sail Plan 018" 2015 sail plan Android Apidemo Devil Step App->alarm->alarm Service

Source: Internet
Author: User

The Alarm service and Alarm Controller examples are very similar, just Alarm service is used to schedule a service, and the previous example is to schedule a broadcast.

As mentioned earlier, pendingintent can be used to describe an activity, broadcast, or a service. This example is schedule a alarm event to start a service. This is typically used to perform a more time-consuming task.

If you write a service that will be followed by a specific example to illustrate, nothing in detail. Just know that Alarmservice_service is a service on the line.

The following code is used to schedule a multiple alarm event to start Alarmservice_service:

Privatependingintent Malarmsender;//Create an intentsender that would launch our service, to be scheduled//With the alarm manager.Malarmsender = Pendingintent.getservice (alarmservice. This, 0,NewIntent (Alarmservice. This, Alarmservice_service.class), 0);...//We want the alarm to go off for seconds from now.LongFirsttime =systemclock.elapsedrealtime ();//Schedule the alarm!Alarmmanager am =(Alarmmanager) Getsystemservice (Alarm_service); Am.setrepeating (Alarmmanager.elapsed_realtime_wakeup, Firsttime,30*1000, Malarmsender);

Cancel this alarm event:

// And cancel the alarm. Alarmmanager am = (alarmmanager) Getsystemservice (Alarm_service); Am.cancel (Malarmsender);

The code is similar to Alaram controller, and the same method can schedule a alarm event to trigger an activity.

"Sail Plan 018" 2015 sail plan Android Apidemo Devil Step App->alarm->alarm Service

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.