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