The Alarm service and the Alarm Controller example are very similar, except that the Alarm service is used to schedule a service, and the previous example is to schedule a broadcast.
Previously said Pendingintent, can describe an activity, broadcast, or a service. This example schedule a alarm event to start a service. This is typically used to perform a more time-consuming task.
If writing a service will be followed by a special example to illustrate, only not in detail. As long as you know Alarmservice_service is a service on the line.
The following code is used to schedule a multiple alarm event to start Alarmservice_service
Private Pendingintent Malarmsender;
...
Create a intentsender that would launch our service, to be scheduled
//with the alarm manager.
Malarmsender = Pendingintent.getservice (Alarmservice.this,
0, New Intent (Alarmservice.this, Alarmservice_ Service.class), 0);
...
We want the "alarm to go" seconds from now.
Long firsttime = 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);
Code is similar to Alaram controller, the same method can schedule a alarm event to trigger an activity.