|
Build 1.0_r1 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectandroid.app.AlarmManager
public class 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).
| Field Summary | |
|---|---|
static int |
ELAPSED_REALTIME
Alarm time in SystemClock.elapsedRealtime() (time since boot, including sleep). |
static int |
ELAPSED_REALTIME_WAKEUP
Alarm time in SystemClock.elapsedRealtime() (time since boot, including sleep), which will wake up the device when it goes off. |
static int |
RTC
Alarm time in System.currentTimeMillis() (wall clock time in UTC). |
static int |
RTC_WAKEUP
Alarm time in System.currentTimeMillis() (wall clock time in UTC), which will wake up the device when it goes off. |
| Method Summary | |
|---|---|
void |
cancel(PendingIntent operation)
Remove any alarms with a matching Intent. |
void |
set(int type,
long triggerAtTime,
PendingIntent operation)
Schedule an alarm. |
void |
setRepeating(int type,
long triggerAtTime,
long interval,
PendingIntent operation)
Schedule a repeating alarm. |
void |
setTimeZone(String timeZone)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int RTC_WAKEUP
public static final int RTC
public static final int ELAPSED_REALTIME_WAKEUP
public static final int ELAPSED_REALTIME
| Method Detail |
|---|
public void set(int type,
long triggerAtTime,
PendingIntent operation)
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(BroadcastReceiver, IntentFilter) or through the <receiver> tag in an AndroidManifest.xml file.
Alarm intents are delivered with a data extra of type int called Intent.EXTRA_ALARM_COUNT that indicates how many past alarm events have been accumulated into this intent broadcast. Recurring alarms that have gone undelivered because the phone was asleep may have a count greater than one when delivered.
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).operation - Action to perform when the alarm goes off;
typically comes from IntentSender.getBroadcast().Handler,
setRepeating(int, long, long, PendingIntent),
cancel(PendingIntent),
sendBroadcast(Intent),
registerReceiver(BroadcastReceiver, IntentFilter),
filterEquals(Intent),
ELAPSED_REALTIME,
ELAPSED_REALTIME_WAKEUP,
RTC,
RTC_WAKEUP
public void setRepeating(int type,
long triggerAtTime,
long interval,
PendingIntent operation)
Like set(int, long, PendingIntent), except you can also supply a rate at which the alarm will repeat. This alarm continues repeating until explicitly removed with cancel(PendingIntent). If the time occurs in the past, the alarm will be triggered immediately, with an alarm count depending on how far in the past the trigger time is relative to the repeat interval.
If an alarm is delayed (by system sleep, for example, for non _WAKEUP alarm types), a skipped repeat will be delivered as soon as possible. After that, future alarms will be delivered according to the original schedule; they do not drift over time. For example, if you have set a recurring alarm for the top of every hour but the phone was asleep from 7:45 until 8:45, an alarm will be sent as soon as the phone awakens, then the next alarm will be sent at 9:00.
If your application wants to allow the delivery times to drift in order to guarantee that at least a certain time interval always elapses between alarms, then the approach to take is to use one-time alarms, scheduling the next one yourself when handling each alarm delivery.
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.operation - Action to perform when the alarm goes off;
typically comes from IntentSender.getBroadcast().Handler,
set(int, long, PendingIntent),
cancel(PendingIntent),
sendBroadcast(Intent),
registerReceiver(BroadcastReceiver, IntentFilter),
filterEquals(Intent),
ELAPSED_REALTIME,
ELAPSED_REALTIME_WAKEUP,
RTC,
RTC_WAKEUPpublic void cancel(PendingIntent operation)
operation - IntentSender which matches a previously added
IntentSender.set(int, long, PendingIntent)public void setTimeZone(String timeZone)
|
Build 1.0_r1 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||