Android Guides | Samples

Android.App.AlarmManager Class

This class provides access to the system alarm services.

See Also: AlarmManager

Syntax

[Android.Runtime.Register("android/app/AlarmManager", DoNotGenerateAcw=true)]
public class AlarmManager : Object

Remarks

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.

The Alarm Manager holds a CPU wake lock as long as the alarm receiver's onReceive() method is executing. This guarantees that the phone will not sleep until you have finished handling the broadcast. Once onReceive() returns, the Alarm Manager releases this wake lock. This means that the phone will in some cases sleep as soon as your onReceive() method completes. If your alarm receiver called Context.StartService(Intent), it is possible that the phone will sleep before the requested service is launched. To prevent this, your BroadcastReceiver and Service will need to implement a separate wake lock policy to ensure that the phone continues running until the service becomes available.

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.

Note: Beginning with API 19 (Build+VERSION_CODES.KitKat) alarm delivery is inexact: the OS will shift alarms in order to minimize wakeups and battery use. There are new APIs to support applications which need strict delivery guarantees; see AlarmManager.SetWindow(AlarmType,Int64,Int64,Int64) and AlarmManager.SetExact(AlarmType,Int64,Int64). Applications whose targetSdkVersion is earlier than API 19 will continue to see the previous behavior in which all alarms are delivered exactly when requested.

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

[Android Documentation]

Requirements

Namespace: Android.App
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 1

The members of Android.App.AlarmManager are listed below.

See Also: Object

Protected Constructors

A constructor used when creating managed representations of JNI objects; called by the runtime.

Public Fields

const
ActionNextAlarmClockChangedString. Broadcast Action: Sent after the value returned by AlarmManager.NextAlarmClock has changed.
const
IntervalDayInt64 (86400000). Available inexact recurrence interval recognized by AlarmManager.SetInexactRepeating(AlarmType,Int64,Int64,Int64) when running on Android prior to API 19.
const
IntervalFifteenMinutesInt64 (900000). Available inexact recurrence interval recognized by AlarmManager.SetInexactRepeating(AlarmType,Int64,Int64,Int64) when running on Android prior to API 19.
const
IntervalHalfDayInt64 (43200000). Available inexact recurrence interval recognized by AlarmManager.SetInexactRepeating(AlarmType,Int64,Int64,Int64) when running on Android prior to API 19.
const
IntervalHalfHourInt64 (1800000). Available inexact recurrence interval recognized by AlarmManager.SetInexactRepeating(AlarmType,Int64,Int64,Int64) when running on Android prior to API 19.
const
IntervalHourInt64 (3600000). Available inexact recurrence interval recognized by AlarmManager.SetInexactRepeating(AlarmType,Int64,Int64,Int64) when running on Android prior to API 19.

Public Properties

[read-only]
NextAlarmClockAlarmManager+AlarmClockInfo. Gets information about the next alarm clock currently scheduled.

Protected Properties

[read-only]
override
ThresholdClassIntPtr. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.
[read-only]
override
ThresholdTypeType. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Public Methods

Cancel(PendingIntent)
Remove any alarms with a matching Intent.
static
FromContext(Context) : AlarmManager
Set(AlarmType, Int64, PendingIntent)
SetAlarmClock(AlarmManager+AlarmClockInfo, PendingIntent)
Schedule an alarm that represents an alarm clock.
SetExact(AlarmType, Int64, PendingIntent)
Schedule an alarm to be delivered precisely at the stated time.
SetInexactRepeating(AlarmType, Int64, Int64, PendingIntent)
Schedule a repeating alarm that has inexact trigger time requirements; for example, an alarm that repeats every hour, but not necessarily at the top of every hour.
SetRepeating(AlarmType, Int64, Int64, PendingIntent)
Schedule a repeating alarm.
SetTime(Int64)
Set the system wall clock time.
SetTimeZone(String)
Sets the system's persistent default time zone.
SetWindow(AlarmType, Int64, Int64, PendingIntent)
Schedule an alarm to be delivered within a given window of time.