AlarmService.javaAPI DocGoogle Android v1.5 Example5385Sun Nov 11 13:01:04 GMT


public class AlarmService extends

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.


App/Service/Alarm Service

Source files

src/com/google/android/samples/app/ The activity that lets you schedule the alarm
src/com/google/android/samples/app/ This is an intent receiver that executes when the alarm goes off
src/com/google/android/samples/app/ 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

Fields Summary
private android.view.View.OnClickListener
private android.view.View.OnClickListener
Constructors Summary
Methods Summary
protected voidonCreate(android.os.Bundle icicle)



        // Watch for button clicks.
        Button button = (Button)findViewById(;
        button = (Button)findViewById(;