public
class
AlarmManager
extends [Object](https://developer.android.com/reference/java/lang/Object) ``
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](https://developer.android.com/reference/android/content/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 …
public
class
AlarmManager
extends [Object](https://developer.android.com/reference/java/lang/Object) ``
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](https://developer.android.com/reference/android/content/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\(\)](https://developer.android.com/reference/android/content/Context#startService(android.content.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](https://developer.android.com/reference/android/os/Handler).
Note: Beginning with API 19 ([Build\.VERSION\_CODES\.KITKAT](https://developer.android.com/reference/android/os/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 [setWindow\(int, long, long, android\.app\.PendingIntent\)](https://developer.android.com/reference/android/app/AlarmManager#setWindow(int,%20long,%20long,%20android.app.PendingIntent)) and [setExact\(int, long, android\.app\.PendingIntent\)](https://developer.android.com/reference/android/app/AlarmManager#setExact(int,%20long,%20android.app.PendingIntent)). Applications whose targetSdkVersion is earlier than API 19 will continue to see the previous behavior in which all alarms are delivered exactly when requested.
Summary
| ### Nested classes | |
|---|---|
class | [AlarmManager\.AlarmClockInfo](https://developer.android.com/reference/android/app/AlarmManager.AlarmClockInfo) An immutable description of a scheduled “alarm clock” event. |
interface | [AlarmManager\.OnAlarmListener](https://developer.android.com/reference/android/app/AlarmManager.OnAlarmListener) Direct-notification alarms: the requester must be running continuously from the time the alarm is set to the time it is delivered, or delivery will fail. |
| ### Constants | |
|---|---|
[String](https://developer.android.com/reference/java/lang/String) | [ACTION\_NEXT\_ALARM\_CLOCK\_CHANGED](https://developer.android.com/reference/android/app/AlarmManager#ACTION_NEXT_ALARM_CLOCK_CHANGED) Broadcast Action: Sent after the value returned by [getNextAlarmClock\(\)](https://developer.android.com/reference/android/app/AlarmManager#getNextAlarmClock()) has changed. |
[String](https://developer.android.com/reference/java/lang/String) | [ACTION\_SCHEDULE\_EXACT\_ALARM\_PERMISSION\_STATE\_CHANGED](https://developer.android.com/reference/android/app/AlarmManager#ACTION_SCHEDULE_EXACT_ALARM_PERMISSION_STATE_CHANGED) Broadcast Action: An app is granted the [Manifest\.permission\.SCHEDULE\_EXACT\_ALARM](https://developer.android.com/reference/android/Manifest.permission#SCHEDULE_EXACT_ALARM) permission. |
int | [ELAPSED\_REALTIME](https://developer.android.com/reference/android/app/AlarmManager#ELAPSED_REALTIME) Alarm time in [SystemClock\.elapsedRealtime\(\)](https://developer.android.com/reference/android/os/SystemClock#elapsedRealtime()) (time since boot, including sleep). |
int | [ELAPSED\_REALTIME\_WAKEUP](https://developer.android.com/reference/android/app/AlarmManager#ELAPSED_REALTIME_WAKEUP) Alarm time in [SystemClock\.elapsedRealtime\(\)](https://developer.android.com/reference/android/os/SystemClock#elapsedRealtime()) (time since boot, including sleep), which will wake up the device when it goes off. |
long | [INTERVAL\_DAY](https://developer.android.com/reference/android/app/AlarmManager#INTERVAL_DAY) Available inexact recurrence interval recognized by [setInexactRepeating\(int, long, long, android\.app\.PendingIntent\)](https://developer.android.com/reference/android/app/AlarmManager#setInexactRepeating(int,%20long,%20long,%20android.app.PendingIntent)) when running on Android prior to API 19. |
long | [INTERVAL\_FIFTEEN\_MINUTES](https://developer.android.com/reference/android/app/AlarmManager#INTERVAL_FIFTEEN_MINUTES) Available inexact recurrence interval recognized by [setInexactRepeating\(int, long, long, android\.app\.PendingIntent\)](https://developer.android.com/reference/android/app/AlarmManager#setInexactRepeating(int,%20long,%20long,%20android.app.PendingIntent)) when running on Android prior to API 19. |
long | [INTERVAL\_HALF\_DAY](https://developer.android.com/reference/android/app/AlarmManager#INTERVAL_HALF_DAY) Available inexact recurrence interval recognized by [setInexactRepeating\(int, long, long, android\.app\.PendingIntent\)](https://developer.android.com/reference/android/app/AlarmManager#setInexactRepeating(int,%20long,%20long,%20android.app.PendingIntent)) when running on Android prior to API 19. |
long | [INTERVAL\_HALF\_HOUR](https://developer.android.com/reference/android/app/AlarmManager#INTERVAL_HALF_HOUR) Available inexact recurrence interval recognized by [setInexactRepeating\(int, long, long, android\.app\.PendingIntent\)](https://developer.android.com/reference/android/app/AlarmManager#setInexactRepeating(int,%20long,%20long,%20android.app.PendingIntent)) when running on Android prior to API 19. |
long | [INTERVAL\_HOUR](https://developer.android.com/reference/android/app/AlarmManager#INTERVAL_HOUR) Available inexact recurrence interval recognized by [setInexactRepeating\(int, long, long, android\.app\.PendingIntent\)](https://developer.android.com/reference/android/app/AlarmManager#setInexactRepeating(int,%20long,%20long,%20android.app.PendingIntent)) when running on Android prior to API 19. |
int | [RTC](https://developer.android.com/reference/android/app/AlarmManager#RTC) Alarm time in [System\.currentTimeMillis\(\)](https://developer.android.com/reference/java/lang/System#currentTimeMillis()) (wall clock time in UTC). |
int | [RTC\_WAKEUP](https://developer.android.com/reference/android/app/AlarmManager#RTC_WAKEUP) Alarm time in [System\.currentTimeMillis\(\)](https://developer.android.com/reference/java/lang/System#currentTimeMillis()) (wall clock time in UTC), which will wake up the device when it goes off. |
| ### Public methods | |
|---|---|
boolean | [canScheduleExactAlarms](https://developer.android.com/reference/android/app/AlarmManager#canScheduleExactAlarms())() Called to check if the caller can schedule exact alarms. |
void | [cancel](https://developer.android.com/reference/android/app/AlarmManager#cancel(android.app.PendingIntent))([PendingIntent](https://developer.android.com/reference/android/app/PendingIntent) operation) Remove any alarms with a matching [Intent](https://developer.android.com/reference/android/content/Intent). |
void | [cancel](https://developer.android.com/reference/android/app/AlarmManager#cancel(android.app.AlarmManager.OnAlarmListener))([AlarmManager\.OnAlarmListener](https://developer.android.com/reference/android/app/AlarmManager.OnAlarmListener) listener) Remove any alarm scheduled to be delivered to the given [OnAlarmListener](https://developer.android.com/reference/android/app/AlarmManager.OnAlarmListener). |
void | [cancelAll](https://developer.android.com/reference/android/app/AlarmManager#cancelAll())() Remove all alarms previously set by the caller, if any. |
[AlarmManager\.AlarmClockInfo](https://developer.android.com/reference/android/app/AlarmManager.AlarmClockInfo) | [getNextAlarmClock](https://developer.android.com/reference/android/app/AlarmManager#getNextAlarmClock())() Gets information about the next alarm clock currently scheduled. |
void | [set](https://developer.android.com/reference/android/app/AlarmManager#set(int,%20long,%20android.app.PendingIntent))(int type, long triggerAtMillis, [PendingIntent](https://developer.android.com/reference/android/app/PendingIntent) operation) Schedule an alarm. |
void | [set](https://developer.android.com/reference/android/app/AlarmManager#set(int,%20long,%20java.lang.String,%20android.app.AlarmManager.OnAlarmListener,%20android.os.Handler))(int type, long triggerAtMillis, [String](https://developer.android.com/reference/java/lang/String) tag, [AlarmManager\.OnAlarmListener](https://developer.android.com/reference/android/app/AlarmManager.OnAlarmListener) listener, [Handler](https://developer.android.com/reference/android/os/Handler) targetHandler) Direct callback version of [set\(int, long, android\.app\.PendingIntent\)](https://developer.android.com/reference/android/app/AlarmManager#set(int,%20long,%20android.app.PendingIntent)). |
void | [setAlarmClock](https://developer.android.com/reference/android/app/AlarmManager#setAlarmClock(android.app.AlarmManager.AlarmClockInfo,%20android.app.PendingIntent))([AlarmManager\.AlarmClockInfo](https://developer.android.com/reference/android/app/AlarmManager.AlarmClockInfo) info, [PendingIntent](https://developer.android.com/reference/android/app/PendingIntent) operation) Schedule an alarm that represents an alarm clock, which will be used to notify the user when it goes off. |
void | [setAndAllowWhileIdle](https://developer.android.com/reference/android/app/AlarmManager#setAndAllowWhileIdle(int,%20long,%20android.app.PendingIntent))(int type, long triggerAtMillis, [PendingIntent](https://developer.android.com/reference/android/app/PendingIntent) operation) Like [set\(int, long, android\.app\.PendingIntent\)](https://developer.android.com/reference/android/app/AlarmManager#set(int,%20long,%20android.app.PendingIntent)), but this alarm will be allowed to execute even when the system is in low-power idle (a.k.a. |
void | [setExact](https://developer.android.com/reference/android/app/AlarmManager#setExact(int,%20long,%20android.app.PendingIntent))(int type, long triggerAtMillis, [PendingIntent](https://developer.android.com/reference/android/app/PendingIntent) operation) Schedule an alarm to be delivered precisely at the stated time. |
void | [setExact](https://developer.android.com/reference/android/app/AlarmManager#setExact(int,%20long,%20java.lang.String,%20android.app.AlarmManager.OnAlarmListener,%20android.os.Handler))(int type, long triggerAtMillis, [String](https://developer.android.com/reference/java/lang/String) tag, [AlarmManager\.OnAlarmListener](https://developer.android.com/reference/android/app/AlarmManager.OnAlarmListener) listener, [Handler](https://developer.android.com/reference/android/os/Handler) targetHandler) Direct callback version of [setExact\(int, long, android\.app\.PendingIntent\)](https://developer.android.com/reference/android/app/AlarmManager#setExact(int,%20long,%20android.app.PendingIntent)). |
void | [setExactAndAllowWhileIdle](https://developer.android.com/reference/android/app/AlarmManager#setExactAndAllowWhileIdle(int,%20long,%20android.app.PendingIntent))(int type, long triggerAtMillis, [PendingIntent](https://developer.android.com/reference/android/app/PendingIntent) operation) Like [setExact\(int, long, android\.app\.PendingIntent\)](https://developer.android.com/reference/android/app/AlarmManager#setExact(int,%20long,%20android.app.PendingIntent)), but this alarm will be allowed to execute even when the system is in low-power idle modes. |
void | [setInexactRepeating](https://developer.android.com/reference/android/app/AlarmManager#setInexactRepeating(int,%20long,%20long,%20android.app.PendingIntent))(int type, long triggerAtMillis, long intervalMillis, [PendingIntent](https://developer.android.com/reference/android/app/PendingIntent) operation) 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. |
void | [setRepeating](https://developer.android.com/reference/android/app/AlarmManager#setRepeating(int,%20long,%20long,%20android.app.PendingIntent))(int type, long triggerAtMillis, long intervalMillis, [PendingIntent](https://developer.android.com/reference/android/app/PendingIntent) operation) Schedule a repeating alarm. |
void | [setTime](https://developer.android.com/reference/android/app/AlarmManager#setTime(long))(long millis) Set the system wall clock time. |
void | [setTimeZone](https://developer.android.com/reference/android/app/AlarmManager#setTimeZone(java.lang.String))([String](https://developer.android.com/reference/java/lang/String) timeZone) Sets the system’s persistent default time zone. |
void | [setWindow](https://developer.android.com/reference/android/app/AlarmManager#setWindow(int,%20long,%20long,%20android.app.PendingIntent))(int type, long windowStartMillis, long windowLengthMillis, [PendingIntent](https://developer.android.com/reference/android/app/PendingIntent) operation) Schedule an alarm to be delivered within a given window of time. |
void | [setWindow](https://developer.android.com/reference/android/app/AlarmManager#setWindow(int,%20long,%20long,%20java.lang.String,%20android.app.AlarmManager.OnAlarmListener,%20android.os.Handler))(int type, long windowStartMillis, long windowLengthMillis, [String](https://developer.android.com/reference/java/lang/String) tag, [AlarmManager\.OnAlarmListener](https://developer.android.com/reference/android/app/AlarmManager.OnAlarmListener) listener, [Handler](https://developer.android.com/reference/android/os/Handler) targetHandler) Direct callback version of [setWindow\(int, long, long, android\.app\.PendingIntent\)](https://developer.android.com/reference/android/app/AlarmManager#setWindow(int,%20long,%20long,%20android.app.PendingIntent)). |
void | [setWindow](https://developer.android.com/reference/android/app/AlarmManager#setWindow(int,%20long,%20long,%20java.lang.String,%20java.util.concurrent.Executor,%20android.app.AlarmManager.OnAlarmListener))(int type, long windowStartMillis, long windowLengthMillis, [String](https://developer.android.com/reference/java/lang/String) tag, [Executor](https://developer.android.com/reference/java/util/concurrent/Executor) executor, [AlarmManager\.OnAlarmListener](https://developer.android.com/reference/android/app/AlarmManager.OnAlarmListener) listener) Direct callback version of [setWindow\(int, long, long, android\.app\.PendingIntent\)](https://developer.android.com/reference/android/app/AlarmManager#setWindow(int,%20long,%20long,%20android.app.PendingIntent)). |
Inherited methods
From class [java\.lang\.Object](https://developer.android.com/reference/java/lang/Object)
[Object](https://developer.android.com/reference/java/lang/Object) | [clone](https://developer.android.com/reference/java/lang/Object#clone())() Creates and returns a copy of this object. |
boolean | [equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))([Object](https://developer.android.com/reference/java/lang/Object) obj) Indicates whether some other object is “equal to” this one. |
void | [finalize](https://developer.android.com/reference/java/lang/Object#finalize())() Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. |
final [Class](https://developer.android.com/reference/java/lang/Class)<?> | [getClass](https://developer.android.com/reference/java/lang/Object#getClass())() Returns the runtime class of this Object. |
int | [hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())() Returns a hash code value for the object. |
| ``` |
final
void
| `[notify](https://developer.android.com/reference/java/lang/Object#notify())()` Wakes up a single thread that is waiting on this object's monitor\. | |
final
void
| `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())()` Wakes up all threads that are waiting on this object's monitor\. | | `[String](https://developer.android.com/reference/java/lang/String)` | `[toString](https://developer.android.com/reference/java/lang/Object#toString())()` Returns a string representation of the object\. | |
final
void
| `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))(long timeoutMillis, int nanos)` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed\. | |
final
void
| `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))(long timeoutMillis)` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed\. | |
final
void
``` | [wait](https://developer.android.com/reference/java/lang/Object#wait())() Causes the current thread to wait until it is awakened, typically by being notified or interrupted. |
Constants
ACTION_NEXT_ALARM_CLOCK_CHANGED
public static final String ACTION_NEXT_ALARM_CLOCK_CHANGED
Broadcast Action: Sent after the value returned by [getNextAlarmClock\(\)](https://developer.android.com/reference/android/app/AlarmManager#getNextAlarmClock()) has changed.
This is a protected intent that can only be sent by the system. It is only sent to registered receivers.
Constant Value: “android.app.action.NEXT_ALARM_CLOCK_CHANGED”
ACTION_SCHEDULE_EXACT_ALARM_PERMISSION_STATE_CHANGED
public static final String ACTION_SCHEDULE_EXACT_ALARM_PERMISSION_STATE_CHANGED
Broadcast Action: An app is granted the [Manifest\.permission\.SCHEDULE\_EXACT\_ALARM](https://developer.android.com/reference/android/Manifest.permission#SCHEDULE_EXACT_ALARM) permission.
When the user revokes the [Manifest\.permission\.SCHEDULE\_EXACT\_ALARM](https://developer.android.com/reference/android/Manifest.permission#SCHEDULE_EXACT_ALARM) permission, all alarms scheduled with [setExact\(int, long, PendingIntent\)](https://developer.android.com/reference/android/app/AlarmManager#setExact(int,%20long,%20android.app.PendingIntent)), [setExactAndAllowWhileIdle\(int, long, PendingIntent\)](https://developer.android.com/reference/android/app/AlarmManager#setExactAndAllowWhileIdle(int,%20long,%20android.app.PendingIntent)) and [setAlarmClock\(android\.app\.AlarmManager\.AlarmClockInfo, android\.app\.PendingIntent\)](https://developer.android.com/reference/android/app/AlarmManager#setAlarmClock(android.app.AlarmManager.AlarmClockInfo,%20android.app.PendingIntent)) will be deleted.
When the user grants the [Manifest\.permission\.SCHEDULE\_EXACT\_ALARM](https://developer.android.com/reference/android/Manifest.permission#SCHEDULE_EXACT_ALARM), this broadcast will be sent. Applications can reschedule all the necessary alarms when receiving it.
This broadcast will not be sent when the user revokes the permission.
Note: Applications are still required to check [canScheduleExactAlarms\(\)](https://developer.android.com/reference/android/app/AlarmManager#canScheduleExactAlarms()) before using the above APIs after receiving this broadcast, because it’s possible that the permission is already revoked again by the time applications receive this broadcast.
This broadcast will be sent to both runtime receivers and manifest receivers.
This broadcast is sent as a foreground broadcast. See [Intent\.FLAG\_RECEIVER\_FOREGROUND](https://developer.android.com/reference/android/content/Intent#FLAG_RECEIVER_FOREGROUND).
When an application receives this broadcast, it’s allowed to start a foreground service.
Constant Value: “android.app.action.SCHEDULE_EXACT_ALARM_PERMISSION_STATE_CHANGED”
ELAPSED_REALTIME
public static final int ELAPSED_REALTIME
Alarm time in [SystemClock\.elapsedRealtime\(\)](https://developer.android.com/reference/android/os/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)
ELAPSED_REALTIME_WAKEUP
public static final int ELAPSED_REALTIME_WAKEUP
Alarm time in [SystemClock\.elapsedRealtime\(\)](https://developer.android.com/reference/android/os/SystemClock#elapsedRealtime()) (time since boot, including sleep), which will wake up the device when it goes off.
Constant Value: 2 (0x00000002)
RTC
public static final int RTC
Alarm time in [System\.currentTimeMillis\(\)](https://developer.android.com/reference/java/lang/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)
RTC_WAKEUP
public static final int RTC_WAKEUP
Alarm time in [System\.currentTimeMillis\(\)](https://developer.android.com/reference/java/lang/System#currentTimeMillis()) (wall clock time in UTC), which will wake up the device when it goes off.
Constant Value: 0 (0x00000000)
Public methods
canScheduleExactAlarms
public boolean canScheduleExactAlarms ()
Called to check if the caller can schedule exact alarms. Your app schedules exact alarms when it calls any of the setExact... or [setAlarmClock](https://developer.android.com/reference/android/app/AlarmManager#setAlarmClock(android.app.AlarmManager.AlarmClockInfo,%20android.app.PendingIntent)) API methods.
Apps targeting [Build\.VERSION\_CODES\.S](https://developer.android.com/reference/android/os/Build.VERSION_CODES#S) or higher can schedule exact alarms only if they have the [Manifest\.permission\.SCHEDULE\_EXACT\_ALARM](https://developer.android.com/reference/android/Manifest.permission#SCHEDULE_EXACT_ALARM) permission or they are on the device’s power-save exemption list. These apps can also start [Settings\.ACTION\_REQUEST\_SCHEDULE\_EXACT\_ALARM](https://developer.android.com/reference/android/provider/Settings#ACTION_REQUEST_SCHEDULE_EXACT_ALARM) to request this permission from the user.
Apps targeting lower sdk versions, can always schedule exact alarms.
| Returns | |
|---|---|
boolean | true if the caller can schedule exact alarms, false otherwise. |
See also:
[Settings\.ACTION\_REQUEST\_SCHEDULE\_EXACT\_ALARM](https://developer.android.com/reference/android/provider/Settings#ACTION_REQUEST_SCHEDULE_EXACT_ALARM)[setExact\(int, long, PendingIntent\)](https://developer.android.com/reference/android/app/AlarmManager#setExact(int,%20long,%20android.app.PendingIntent))[setExactAndAllowWhileIdle\(int, long, PendingIntent\)](https://developer.android.com/reference/android/app/AlarmManager#setExactAndAllowWhileIdle(int,%20long,%20android.app.PendingIntent))[setAlarmClock\(AlarmClockInfo, PendingIntent\)](https://developer.android.com/reference/android/app/AlarmManager#setAlarmClock(android.app.AlarmManager.AlarmClockInfo,%20android.app.PendingIntent))[PowerManager\.isIgnoringBatteryOptimizations\(String\)](https://developer.android.com/reference/android/os/PowerManager#isIgnoringBatteryOptimizations(java.lang.String))
cancel
public void cancel (PendingIntent operation)
Remove any alarms with a matching [Intent](https://developer.android.com/reference/android/content/Intent). Any alarm, of any type, whose Intent matches this one (as defined by [Intent\.filterEquals](https://developer.android.com/reference/android/content/Intent#filterEquals(android.content.Intent))), will be canceled.
| Parameters | |
|---|---|
operation | PendingIntent: IntentSender which matches a previously added IntentSender. This parameter must not be null. |
cancel
public void cancel (AlarmManager.OnAlarmListener listener)
Remove any alarm scheduled to be delivered to the given [OnAlarmListener](https://developer.android.com/reference/android/app/AlarmManager.OnAlarmListener).
| Parameters | |
|---|---|
listener | AlarmManager.OnAlarmListener: OnAlarmListener instance that is the target of a currently-set alarm. This value cannot be null. |
cancelAll
public void cancelAll ()
Remove all alarms previously set by the caller, if any.
getNextAlarmClock
public AlarmManager.AlarmClockInfo getNextAlarmClock ()
Gets information about the next alarm clock currently scheduled. The alarm clocks considered are those scheduled by any application using the [setAlarmClock\(AlarmClockInfo, PendingIntent\)](https://developer.android.com/reference/android/app/AlarmManager#setAlarmClock(android.app.AlarmManager.AlarmClockInfo,%20android.app.PendingIntent)) method.
| Returns | |
|---|---|
[AlarmManager\.AlarmClockInfo](https://developer.android.com/reference/android/app/AlarmManager.AlarmClockInfo) | An [AlarmClockInfo](https://developer.android.com/reference/android/app/AlarmManager.AlarmClockInfo) object describing the next upcoming alarm clock event that will occur. If there are no alarm clock events currently scheduled, this method will return null. |
See also:
[setAlarmClock\(AlarmClockInfo, PendingIntent\)](https://developer.android.com/reference/android/app/AlarmManager#setAlarmClock(android.app.AlarmManager.AlarmClockInfo,%20android.app.PendingIntent))[AlarmManager\.AlarmClockInfo](https://developer.android.com/reference/android/app/AlarmManager.AlarmClockInfo)[ACTION\_NEXT\_ALARM\_CLOCK\_CHANGED](https://developer.android.com/reference/android/app/AlarmManager#ACTION_NEXT_ALARM_CLOCK_CHANGED)
set
public void set (int type,
long triggerAtMillis,
PendingIntent operation)
Schedule an alarm. Note: for timing operations (ticks, timeouts, etc) it is easier and much more efficient to use [Handler](https://developer.android.com/reference/android/os/Handler). If there is already an alarm scheduled for the same IntentSender, that previous alarm will first be canceled.
If the stated trigger time is 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 [Intent\.filterEquals](https://developer.android.com/reference/android/content/Intent#filterEquals(android.content.Intent))), then it will be removed and replaced by this one.
The alarm is an Intent broadcast that goes to a broadcast receiver that you registered with [Context\.registerReceiver\(BroadcastReceiver, IntentFilter\)](https://developer.android.com/reference/android/content/Context#registerReceiver(android.content.BroadcastReceiver,%20android.content.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](https://developer.android.com/reference/android/content/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.
Note: Beginning in API 19, the trigger time passed to this method is treated as inexact: the alarm will not be delivered before this time, but may be deferred and delivered some time later. The OS will use this policy in order to “batch” alarms together across the entire system, minimizing the number of times the device needs to “wake up” and minimizing battery use. In general, alarms scheduled in the near future will not be deferred as long as alarms scheduled far in the future.
With the new batching policy, delivery ordering guarantees are not as strong as they were previously. If the application sets multiple alarms, it is possible that these alarms’ actual delivery ordering may not match the order of their requested delivery times. If your application has strong ordering requirements there are other APIs that you can use to get the necessary behavior; see [setWindow\(int, long, long, android\.app\.PendingIntent\)](https://developer.android.com/reference/android/app/AlarmManager#setWindow(int,%20long,%20long,%20android.app.PendingIntent)) and [setExact\(int, long, android\.app\.PendingIntent\)](https://developer.android.com/reference/android/app/AlarmManager#setExact(int,%20long,%20android.app.PendingIntent)).
Applications whose targetSdkVersion is before API 19 will continue to get the previous alarm behavior: all of their scheduled alarms will be treated as exact.
| Parameters | |
|---|---|
type | int: type of alarm. Value is [RTC\_WAKEUP](https://developer.android.com/reference/android/app/AlarmManager#RTC_WAKEUP), [RTC](https://developer.android.com/reference/android/app/AlarmManager#RTC), [ELAPSED\_REALTIME\_WAKEUP](https://developer.android.com/reference/android/app/AlarmManager#ELAPSED_REALTIME_WAKEUP), or [ELAPSED\_REALTIME](https://developer.android.com/reference/android/app/AlarmManager#ELAPSED_REALTIME) |
triggerAtMillis | long: time in milliseconds that the alarm should go off, using the appropriate clock (depending on the alarm type). |
operation | PendingIntent: Action to perform when the alarm goes off; typically comes from [IntentSender\.getBroadcast\(\)](https://developer.android.com/reference/android/app/PendingIntent#getBroadcast(android.content.Context,%20int,%20android.content.Intent,%20int)). This value cannot be null. |
See also:
[Handler](https://developer.android.com/reference/android/os/Handler)[setExact\(int, long, PendingIntent\)](https://developer.android.com/reference/android/app/AlarmManager#setExact(int,%20long,%20android.app.PendingIntent))[setRepeating\(int, long, long, PendingIntent\)](https://developer.android.com/reference/android/app/AlarmManager#setRepeating(int,%20long,%20long,%20android.app.PendingIntent))[setWindow\(int, long, long, PendingIntent\)](https://developer.android.com/reference/android/app/AlarmManager#setWindow(int,%20long,%20long,%20android.app.PendingIntent))[cancel\(OnAlarmListener\)](https://developer.android.com/reference/android/app/AlarmManager#cancel(android.app.AlarmManager.OnAlarmListener))[Context\.sendBroadcast\(Intent\)](https://developer.android.com/reference/android/content/Context#sendBroadcast(android.content.Intent))[Context\.registerReceiver\(BroadcastReceiver, IntentFilter\)](https://developer.android.com/reference/android/content/Context#registerReceiver(android.content.BroadcastReceiver,%20android.content.IntentFilter))[Intent\.filterEquals\(Intent\)](https://developer.android.com/reference/android/content/Intent#filterEquals(android.content.Intent))[ELAPSED\_REALTIME](https://developer.android.com/reference/android/app/AlarmManager#ELAPSED_REALTIME)[ELAPSED\_REALTIME\_WAKEUP](https://developer.android.com/reference/android/app/AlarmManager#ELAPSED_REALTIME_WAKEUP)[RTC](https://developer.android.com/reference/android/app/AlarmManager#RTC)[RTC\_WAKEUP](https://developer.android.com/reference/android/app/AlarmManager#RTC_WAKEUP)
set
public void set (int type,
long triggerAtMillis,
String tag,
AlarmManager.OnAlarmListener listener,
Handler targetHandler)
Direct callback version of [set\(int, long, android\.app\.PendingIntent\)](https://developer.android.com/reference/android/app/AlarmManager#set(int,%20long,%20android.app.PendingIntent)). Rather than supplying a PendingIntent to be sent when the alarm time is reached, this variant supplies an [OnAlarmListener](https://developer.android.com/reference/android/app/AlarmManager.OnAlarmListener) instance that will be invoked at that time.
The OnAlarmListener’s [onAlarm\(\)](https://developer.android.com/reference/android/app/AlarmManager.OnAlarmListener#onAlarm()) method will be invoked via the specified target Handler, or on the application’s main looper if null is passed as the targetHandler parameter.
| Parameters | |
|---|---|
type | int: type of alarm. Value is [RTC\_WAKEUP](https://developer.android.com/reference/android/app/AlarmManager#RTC_WAKEUP), [RTC](https://developer.android.com/reference/android/app/AlarmManager#RTC), [ELAPSED\_REALTIME\_WAKEUP](https://developer.android.com/reference/android/app/AlarmManager#ELAPSED_REALTIME_WAKEUP), or [ELAPSED\_REALTIME](https://developer.android.com/reference/android/app/AlarmManager#ELAPSED_REALTIME) |
triggerAtMillis | long: time in milliseconds that the alarm should go off, using the appropriate clock (depending on the alarm type). |
tag | String: string describing the alarm, used for logging and battery-use attribution This value may be null. |
listener | AlarmManager.OnAlarmListener: [OnAlarmListener](https://developer.android.com/reference/android/app/AlarmManager.OnAlarmListener) instance whose [onAlarm\(\)](https://developer.android.com/reference/android/app/AlarmManager.OnAlarmListener#onAlarm()) method will be called when the alarm time is reached. A given OnAlarmListener instance can only be the target of a single pending alarm, just as a given PendingIntent can only be used with one alarm at a time. This value cannot be null. |
targetHandler | Handler: [Handler](https://developer.android.com/reference/android/os/Handler) on which to execute the listener’s onAlarm() callback, or null to run that callback on the main looper. |
setAlarmClock
public void setAlarmClock (AlarmManager.AlarmClockInfo info,
PendingIntent operation)
Schedule an alarm that represents an alarm clock, which will be used to notify the user when it goes off. The expectation is that when this alarm triggers, the application will further wake up the device to tell the user about the alarm – turning on the screen, playing a sound, vibrating, etc. As such, the system will typically also use the information supplied here to tell the user about this upcoming alarm if appropriate.
Due to the nature of this kind of alarm, similar to [setExactAndAllowWhileIdle\(int, long, PendingIntent\)](https://developer.android.com/reference/android/app/AlarmManager#setExactAndAllowWhileIdle(int,%20long,%20android.app.PendingIntent)), these alarms will be allowed to trigger even if the system is in a low-power idle (a.k.a. doze) mode. The system may also do some prep-work when it sees that such an alarm coming up, to reduce the amount of background work that could happen if this causes the device to fully wake up – this is to avoid situations such as a large number of devices having an alarm set at the same time in the morning, all waking up at that time and suddenly swamping the network with pending background work. As such, these types of alarms can be extremely expensive on battery use and should only be used for their intended purpose.
This method is like [setExact\(int, long, android\.app\.PendingIntent\)](https://developer.android.com/reference/android/app/AlarmManager#setExact(int,%20long,%20android.app.PendingIntent)), but implies [RTC\_WAKEUP](https://developer.android.com/reference/android/app/AlarmManager#RTC_WAKEUP).
Note: Starting with [Build\.VERSION\_CODES\.S](https://developer.android.com/reference/android/os/Build.VERSION_CODES#S), apps targeting SDK level 31 or higher need to request the [SCHEDULE\_EXACT\_ALARM](https://developer.android.com/reference/android/Manifest.permission#SCHEDULE_EXACT_ALARM) permission to use this API. The user and the system can revoke this permission via the special app access screen in Settings.
Note: Exact alarms should only be used for user-facing features. For more details, see Exact alarm permission.
Alarms scheduled via this API will be allowed to start a foreground service even if the app is in the background.
Requires [Manifest\.permission\.SCHEDULE\_EXACT\_ALARM](https://developer.android.com/reference/android/Manifest.permission#SCHEDULE_EXACT_ALARM)
| Parameters | |
|---|---|
info | AlarmManager.AlarmClockInfo: This value cannot be null. |
operation | PendingIntent: Action to perform when the alarm goes off; typically comes from [IntentSender\.getBroadcast\(\)](https://developer.android.com/reference/android/app/PendingIntent#getBroadcast(android.content.Context,%20int,%20android.content.Intent,%20int)). This value cannot be null. |
See also:
[set\(int, long, PendingIntent\)](https://developer.android.com/reference/android/app/AlarmManager#set(int,%20long,%20android.app.PendingIntent))[setRepeating\(int, long, long, PendingIntent\)](https://developer.android.com/reference/android/app/AlarmManager#setRepeating(int,%20long,%20long,%20android.app.PendingIntent))[setWindow\(int, long, long, PendingIntent\)](https://developer.android.com/reference/android/app/AlarmManager#setWindow(int,%20long,%20long,%20android.app.PendingIntent))[setExact\(int, long, PendingIntent\)](https://developer.android.com/reference/android/app/AlarmManager#setExact(int,%20long,%20android.app.PendingIntent))[cancel\(OnAlarmListener\)](https://developer.android.com/reference/android/app/AlarmManager#cancel(android.app.AlarmManager.OnAlarmListener))[getNextAlarmClock\(\)](https://developer.android.com/reference/android/app/AlarmManager#getNextAlarmClock())[Context\.sendBroadcast\(Intent\)](https://developer.android.com/reference/android/content/Context#sendBroadcast(android.content.Intent))[Context\.registerReceiver\(BroadcastReceiver, IntentFilter\)](https://developer.android.com/reference/android/content/Context#registerReceiver(android.content.BroadcastReceiver,%20android.content.IntentFilter))[Intent\.filterEquals\(Intent\)](https://developer.android.com/reference/android/content/Intent#filterEquals(android.content.Intent))[SCHEDULE\_EXACT\_ALARM](https://developer.android.com/reference/android/Manifest.permission#SCHEDULE_EXACT_ALARM)
setAndAllowWhileIdle
public void setAndAllowWhileIdle (int type,
long triggerAtMillis,
PendingIntent operation)
Like [set\(int, long, android\.app\.PendingIntent\)](https://developer.android.com/reference/android/app/AlarmManager#set(int,%20long,%20android.app.PendingIntent)), but this alarm will be allowed to execute even when the system is in low-power idle (a.k.a. doze) modes. This type of alarm must only be used for situations where it is actually required that the alarm go off while in idle – a reasonable example would be for a calendar notification that should make a sound so the user is aware of it. When the alarm is dispatched, the app will also be added to the system’s temporary power exemption list for approximately 10 seconds to allow that application to acquire further wake locks in which to complete its work.
These alarms can significantly impact the power use of the device when idle (and thus cause significant battery blame to the app scheduling them), so they should be used with care. To reduce abuse, there are restrictions on how frequently these alarms will go off for a particular application. Under normal system operation, it will not dispatch these alarms more than about every minute (at which point every such pending alarm is dispatched); when in low-power idle modes this duration may be significantly longer, such as 15 minutes.
Unlike other alarms, the system is free to reschedule this type of alarm to happen out of order with any other alarms, even those from the same app. This will clearly happen when the device is idle (since this alarm can go off while idle, when any other alarms from the app will be held until later), but may also happen even when not idle.
Regardless of the app’s target SDK version, this call always allows batching of the alarm.
| Parameters | |
|---|---|
type | int: type of alarm. Value is [RTC\_WAKEUP](https://developer.android.com/reference/android/app/AlarmManager#RTC_WAKEUP), [RTC](https://developer.android.com/reference/android/app/AlarmManager#RTC), [ELAPSED\_REALTIME\_WAKEUP](https://developer.android.com/reference/android/app/AlarmManager#ELAPSED_REALTIME_WAKEUP), or [ELAPSED\_REALTIME](https://developer.android.com/reference/android/app/AlarmManager#ELAPSED_REALTIME) |
triggerAtMillis | long: time in milliseconds that the alarm should go off, using the appropriate clock (depending on the alarm type). |
operation | PendingIntent: Action to perform when the alarm goes off; typically comes from [IntentSender\.getBroadcast\(\)](https://developer.android.com/reference/android/app/PendingIntent#getBroadcast(android.content.Context,%20int,%20android.content.Intent,%20int)). This value cannot be null. |
See also:
[set\(int, long, PendingIntent\)](https://developer.android.com/reference/android/app/AlarmManager#set(int,%20long,%20android.app.PendingIntent))[setExactAndAllowWhileIdle\(int, long, PendingIntent\)](https://developer.android.com/reference/android/app/AlarmManager#setExactAndAllowWhileIdle(int,%20long,%20android.app.PendingIntent))[cancel\(OnAlarmListener\)](https://developer.android.com/reference/android/app/AlarmManager#cancel(android.app.AlarmManager.OnAlarmListener))[Context\.sendBroadcast\(Intent\)](https://developer.android.com/reference/android/content/Context#sendBroadcast(android.content.Intent))[Context\.registerReceiver\(BroadcastReceiver, IntentFilter\)](https://developer.android.com/reference/android/content/Context#registerReceiver(android.content.BroadcastReceiver,%20android.content.IntentFilter))[Intent\.filterEquals\(Intent\)](https://developer.android.com/reference/android/content/Intent#filterEquals(android.content.Intent))[ELAPSED\_REALTIME](https://developer.android.com/reference/android/app/AlarmManager#ELAPSED_REALTIME)[ELAPSED\_REALTIME\_WAKEUP](https://developer.android.com/reference/android/app/AlarmManager#ELAPSED_REALTIME_WAKEUP)[RTC](https://developer.android.com/reference/android/app/AlarmManager#RTC)[RTC\_WAKEUP](https://developer.android.com/reference/android/app/AlarmManager#RTC_WAKEUP)
setExact
public void setExact (int type,
long triggerAtMillis,
PendingIntent operation)
Schedule an alarm to be delivered precisely at the stated time.
This method is like [set\(int, long, android\.app\.PendingIntent\)](https://developer.android.com/reference/android/app/AlarmManager#set(int,%20long,%20android.app.PendingIntent)), but does not permit the OS to adjust the delivery time. The alarm will be delivered as nearly as possible to the requested trigger time.
Note: only alarms for which there is a strong demand for exact-time delivery (such as an alarm clock ringing at the requested time) should be scheduled as exact. Applications are strongly discouraged from using exact alarms unnecessarily as they reduce the OS’s ability to minimize battery use.
Note: Starting with [Build\.VERSION\_CODES\.S](https://developer.android.com/reference/android/os/Build.VERSION_CODES#S), apps targeting SDK level 31 or higher need to request the [SCHEDULE\_EXACT\_ALARM](https://developer.android.com/reference/android/Manifest.permission#SCHEDULE_EXACT_ALARM) permission to use this API, unless the app is exempt from battery restrictions. The user and the system can revoke this permission via the special app access screen in Settings.
Note: Exact alarms should only be used for user-facing features. For more details, see Exact alarm permission.
| Parameters | |
|---|---|
type | int: type of alarm. Value is [RTC\_WAKEUP](https://developer.android.com/reference/android/app/AlarmManager#RTC_WAKEUP), [RTC](https://developer.android.com/reference/android/app/AlarmManager#RTC), [ELAPSED\_REALTIME\_WAKEUP](https://developer.android.com/reference/android/app/AlarmManager#ELAPSED_REALTIME_WAKEUP), or [ELAPSED\_REALTIME](https://developer.android.com/reference/android/app/AlarmManager#ELAPSED_REALTIME) |
triggerAtMillis | long: time in milliseconds that the alarm should go off, using the appropriate clock (depending on the alarm type). |
operation | PendingIntent: Action to perform when the alarm goes off; typically comes from [IntentSender\.getBroadcast\(\)](https://developer.android.com/reference/android/app/PendingIntent#getBroadcast(android.content.Context,%20int,%20android.content.Intent,%20int)). This value cannot be null. |
See also:
[set\(int, long, PendingIntent\)](https://developer.android.com/reference/android/app/AlarmManager#set(int,%20long,%20android.app.PendingIntent))[setRepeating\(int, long, long, PendingIntent\)](https://developer.android.com/reference/android/app/AlarmManager#setRepeating(int,%20long,%20long,%20android.app.PendingIntent))[setWindow\(int, long, long, PendingIntent\)](https://developer.android.com/reference/android/app/AlarmManager#setWindow(int,%20long,%20long,%20android.app.PendingIntent))[cancel\(OnAlarmListener\)](https://developer.android.com/reference/android/app/AlarmManager#cancel(android.app.AlarmManager.OnAlarmListener))[Context\.sendBroadcast\(Intent\)](https://developer.android.com/reference/android/content/Context#sendBroadcast(android.content.Intent))[Context\.registerReceiver\(BroadcastReceiver, IntentFilter\)](https://developer.android.com/reference/android/content/Context#registerReceiver(android.content.BroadcastReceiver,%20android.content.IntentFilter))[Intent\.filterEquals\(Intent\)](https://developer.android.com/reference/android/content/Intent#filterEquals(android.content.Intent))[ELAPSED\_REALTIME](https://developer.android.com/reference/android/app/AlarmManager#ELAPSED_REALTIME)[ELAPSED\_REALTIME\_WAKEUP](https://developer.android.com/reference/android/app/AlarmManager#ELAPSED_REALTIME_WAKEUP)[RTC](https://developer.android.com/reference/android/app/AlarmManager#RTC)[RTC\_WAKEUP](https://developer.android.com/reference/android/app/AlarmManager#RTC_WAKEUP)[SCHEDULE\_EXACT\_ALARM](https://developer.android.com/reference/android/Manifest.permission#SCHEDULE_EXACT_ALARM)
setExact
public void setExact (int type,
long triggerAtMillis,
String tag,
AlarmManager.OnAlarmListener listener,
Handler targetHandler)
Direct callback version of [setExact\(int, long, android\.app\.PendingIntent\)](https://developer.android.com/reference/android/app/AlarmManager#setExact(int,%20long,%20android.app.PendingIntent)). Rather than supplying a PendingIntent to be sent when the alarm time is reached, this variant supplies an [OnAlarmListener](https://developer.android.com/reference/android/app/AlarmManager.OnAlarmListener) instance that will be invoked at that time.
The OnAlarmListener’s [onAlarm\(\)](https://developer.android.com/reference/android/app/AlarmManager.OnAlarmListener#onAlarm()) method will be invoked via the specified target Handler, or on the application’s main looper if null is passed as the targetHandler parameter.
This API should only be used to set alarms that are relevant in the context of the app’s current lifecycle, as the [OnAlarmListener](https://developer.android.com/reference/android/app/AlarmManager.OnAlarmListener) instance supplied is only valid as long as the process is alive, and the system can clean up the app process as soon as it is out of lifecycle. To schedule alarms that fire reliably even after the current lifecycle completes, and wakes up the app if required, use any of the other scheduling APIs that accept a [PendingIntent](https://developer.android.com/reference/android/app/PendingIntent) instance.
On previous android versions [Build\.VERSION\_CODES\.S](https://developer.android.com/reference/android/os/Build.VERSION_CODES#S) and [Build\.VERSION\_CODES\.TIRAMISU](https://developer.android.com/reference/android/os/Build.VERSION_CODES#TIRAMISU), apps targeting SDK level 31 or higher needed to hold the [SCHEDULE\_EXACT\_ALARM](https://developer.android.com/reference/android/Manifest.permission#SCHEDULE_EXACT_ALARM) permission to use this API, unless the app was exempt from battery restrictions.
Note: Starting with android version `[Build.VERSION_CODES.UPSIDE_DOWN_CAKE]