Example of scheduling one-shot and repeating alarms. See
{@link OneShotAlarm} for the code run when the one-shot alarm goes off, and
{@link RepeatingAlarm} for the code run when the repeating alarm goes off.
This demonstrates a very common background that puts together both alarms
and service: a regularily scheduled alarm that results in the execution of
a relatively long-lived service. An example of where you would use this is
for background retrieval of mail. In this situation, you don't want to
retrieve the mail directly in the alarm's intent receiver, because this would
block others while you are working. Instead, the alarm starts a service that
takes care of retrieving the mail.
Demo
App/Service/Alarm Service
Source files
src/com/google/android/samples/app/AlarmService.java |
The activity that lets you schedule the alarm |
src/com/google/android/samples/app/AlarmService_Alarm.java |
This is an intent receiver that executes when the
alarm goes off |
src/com/google/android/samples/app/AlarmService_Service.java |
This is the service that implements our background action,
which is started by the AlarmService_Alarm |
/res/any/layout/alarm_service.xml |
Defines contents of the screen |
|