English | Site Directory

Android - An Open Handset Alliance Project

android.app
public class

android.app.AlarmManager

java.lang.Object
android.app.AlarmManager

This class provides access to the system alarm services. These allow you to schedule your application to be run at some point in the future. When an alarm goes off, the Intent that had been registered for it is broadcast by the system, automatically starting the target application if it is not already running. Registered alarms are retained while the device is asleep (and can optionally wake the device up if they go off during that time), but will be cleared if it is turned off and rebooted.

Note: The Alarm Manager is intended for cases where you want to have your application code run at a specific time, even if your application is not currently running. For normal timing operations (ticks, timeouts, etc) it is easier and much more efficient to use Handler.

You do not instantiate this class directly; instead, retrieve it through Context.getSystemService(Context.ALARM_SERVICE).

Summary

Constants

      Value  
int  ELAPSED_REALTIME  Alarm time in SystemClock.elapsedRealtime() (time since boot, including sleep).  0x00000003 
int  ELAPSED_REALTIME_WAKEUP  Alarm time in SystemClock.elapsedRealtime() (time since boot, including sleep), which will wake up the device when it goes off.  0x00000002 
int  RTC  Alarm time in System.currentTimeMillis() (wall clock time in UTC).  0x00000001 
int  RTC_WAKEUP  Alarm time in System.currentTimeMillis() (wall clock time in UTC), which will wake up the device when it goes off.  0x00000000 

Public Methods

        void  cancel(Intent intent)
Remove any alarms with a matching Intent.
        void  set(int type, long triggerAtTime, Intent intent)
Schedule an alarm.
        void  setRepeating(int type, long triggerAtTime, long interval, Intent intent)
Schedule a repeating alarm.
Methods inherited from class java.lang.Object

Details

Constants

public static final int ELAPSED_REALTIME

Alarm time in SystemClock.elapsedRealtime() (time since boot, including sleep). This alarm does not wake the device up; if it goes off while the device is asleep, it will not be delivered until the next time the device wakes up.
Constant Value: 3 (0x00000003)

public static final int ELAPSED_REALTIME_WAKEUP

Alarm time in SystemClock.elapsedRealtime() (time since boot, including sleep), which will wake up the device when it goes off.
Constant Value: 2 (0x00000002)

public static final int RTC

Alarm time in System.currentTimeMillis() (wall clock time in UTC). This alarm does not wake the device up; if it goes off while the device is asleep, it will not be delivered until the next time the device wakes up.
Constant Value: 1 (0x00000001)

public static final int RTC_WAKEUP

Alarm time in System.currentTimeMillis() (wall clock time in UTC), which will wake up the device when it goes off.
Constant Value: 0 (0x00000000)

Public Methods

public void cancel(Intent intent)

Remove any alarms with a matching Intent. Any alarm, of any type, whose Intent matches this one (as defined by filterEquals(Intent)), will be cancelled.

Parameters

intent which matches the Intent of alarms to remove.

public void set(int type, long triggerAtTime, Intent intent)

Schedule an alarm. Note: for timing operations (ticks, timeouts, etc) it is easier and much more efficient to use Handler.

If the time occurs in the past, the alarm will be triggered immediately. If there is already an alarm for this Intent scheduled (with the equality of two intents being defined by filterEquals(Intent)), then it will be removed and replaced by this one.

The alarm is an intent broadcast that goes to an intent receiver that you registered with registerReceiver(IntentReceiver, IntentFilter) or through the <receiver> tag in an AndroidManifest.xml file.

Parameters

type One of ELAPSED_REALTIME, ELAPSED_REALTIME_WAKEUP, RTC or RTC_WAKEUP.
triggerAtTime Time the alarm should go off, using the appropriate clock (depending on the alarm type).
intent The intent to send.

public void setRepeating(int type, long triggerAtTime, long interval, Intent intent)

Schedule a repeating alarm. Note: for timing operations (ticks, timeouts, etc) it is easier and much more efficient to use Handler.

Like set(int, long, Intent), except you can also supply a rate at which the alarm will repeat. This alarm continues repeating until explicitly removed with cancel(Intent). If the time occurs in the past, the alarm will be triggered immediately, and repeats begin as usual after the specified interval.

If an alarm is delayed (by system sleep, for example, for non _WAKEUP alarm types), the next repeat is not triggered until the appropriate interval after the last trigger actually took place; the repeat interval is a minimum, not a maximum. This means the alarm can "drift", so a repeating alarm should not be used (for example) to trigger some action precisely at the top of every hour.

Parameters

type One of ELAPSED_REALTIME, ELAPSED_REALTIME_WAKEUP}, RTC or RTC_WAKEUP.
triggerAtTime Time the alarm should first go off, using the appropriate clock (depending on the alarm type).
interval Interval between subsequent repeats of the alarm.
intent The intent to send.
Build m5-rc15g - 14 May 2008 12:50