Dil

AlarmManager.SetWindow Method

Definition

Overloads

Name Description
SetWindow(AlarmType, Int64, Int64, PendingIntent)

Schedule an alarm to be delivered within a given window of time.

SetWindow(AlarmType, Int64, Int64, String, AlarmManager+IOnAlarmListener, Handler)

Direct callback version of setWindow(int,long,long,PendingIntent).

SetWindow(AlarmType, Int64, Int64, String, IExecutor, AlarmManager+IOnAlarmListener)

Direct callback version of setWindow(int,long,long,PendingIntent).

SetWindow(AlarmType, Int64, Int64, PendingIntent)

Schedule an alarm to be delivered within a given window of time.

[Android.Runtime.Register("setWindow", "(IJJLandroid/app/PendingIntent;)V", "GetSetWindow_IJJLandroid_app_PendingIntent_Handler")]
public virtual void SetWindow(Android.App.AlarmType type, long windowStartMillis, long windowLengthMillis, Android.App.PendingIntent operation);
[<Android.Runtime.Register("setWindow", "(IJJLandroid/app/PendingIntent;)V", "GetSetWindow_IJJLandroid_app_PendingIntent_Handler")>]
abstract member SetWindow : Android.App.AlarmType * int64 * int64 * Android.App.PendingIntent -> unit
override this.SetWindow : Android.App.AlarmType * int64 * int64 * Android.App.PendingIntent -> unit

Parameters

type
AlarmType

int: type of alarm. Value is one of the following: RTC_WAKEUP RTC ELAPSED_REALTIME_WAKEUP ELAPSED_REALTIME

windowStartMillis
Int64

long: The earliest time, in milliseconds, that the alarm should be delivered, expressed in the appropriate clock's units (depending on the alarm type).

windowLengthMillis
Int64

long: The length of the requested delivery window, in milliseconds. The alarm will be delivered no later than this many milliseconds after windowStartMillis. Note that this parameter is a duration, not the timestamp of the end of the window.

operation
PendingIntent

PendingIntent: Action to perform when the alarm goes off; typically comes from IntentSender.getBroadcast(). This value cannot be null.

Attributes

Remarks

Schedule an alarm to be delivered within a given window of time. This method is similar to set(int,long,PendingIntent), but allows the application to precisely control the degree to which its delivery might be adjusted by the OS. This method allows an application to take advantage of the battery optimizations that arise from delivery batching even when it has modest timeliness requirements for its alarms. Note: Starting with API Build.VERSION_CODES.S, apps should not pass in a window of less than 10 minutes. The system will try its best to accommodate smaller windows if the alarm is supposed to fire in the near future, but there are no guarantees and the app should expect any window smaller than 10 minutes to get elongated to 10 minutes. This method can also be used to achieve strict ordering guarantees among multiple alarms by ensuring that the windows requested for each alarm do not intersect. When precise delivery is not required, applications should use the standard set(int,long,PendingIntent) method. This will give the OS the most flexibility to minimize wakeups and battery use. For alarms that must be delivered at precisely-specified times with no acceptable variation, applications can use setExact(int,long,PendingIntent).

See also:

Android reference for android.app.AlarmManager.setWindow.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

SetWindow(AlarmType, Int64, Int64, String, AlarmManager+IOnAlarmListener, Handler)

Direct callback version of setWindow(int,long,long,PendingIntent).

[Android.Runtime.Register("setWindow", "(IJJLjava/lang/String;Landroid/app/AlarmManager$OnAlarmListener;Landroid/os/Handler;)V", "GetSetWindow_IJJLjava_lang_String_Landroid_app_AlarmManager_OnAlarmListener_Landroid_os_Handler_Handler", ApiSince=24)]
public virtual void SetWindow(Android.App.AlarmType type, long windowStartMillis, long windowLengthMillis, string? tag, Android.App.AlarmManager.IOnAlarmListener listener, Android.OS.Handler? targetHandler);
[<Android.Runtime.Register("setWindow", "(IJJLjava/lang/String;Landroid/app/AlarmManager$OnAlarmListener;Landroid/os/Handler;)V", "GetSetWindow_IJJLjava_lang_String_Landroid_app_AlarmManager_OnAlarmListener_Landroid_os_Handler_Handler", ApiSince=24)>]
abstract member SetWindow : Android.App.AlarmType * int64 * int64 * string * Android.App.AlarmManager.IOnAlarmListener * Android.OS.Handler -> unit
override this.SetWindow : Android.App.AlarmType * int64 * int64 * string * Android.App.AlarmManager.IOnAlarmListener * Android.OS.Handler -> unit

Parameters

type
AlarmType

int: Value is one of the following: RTC_WAKEUP RTC ELAPSED_REALTIME_WAKEUP ELAPSED_REALTIME

windowStartMillis
Int64

long

windowLengthMillis
Int64

long

tag
String

String: This value may be null.

listener
AlarmManager.IOnAlarmListener

AlarmManager.OnAlarmListener: This value cannot be null.

targetHandler
Handler

Handler: This value may be null.

Attributes

Remarks

Direct callback version of setWindow(int,long,long,PendingIntent). Rather than supplying a PendingIntent to be sent when the alarm time is reached, this variant supplies an OnAlarmListener instance that will be invoked at that time. Listener based alarms may be canceled by the Android system whenever the calling process no longer has any components running, such as Activity, Service, or ContentProvider, so only use these APIs when you do not need to receive alarms after the current component finishes, and also make sure to cancel(OnAlarmListener) them when it does. For example, if you use these APIs from an Activity, make sure to cancel the respective alarms when the activity finishes. If you need to receive the alarm even after that, use the PendingIntent based APIs. The 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. Note: Starting with API Build.VERSION_CODES.S, apps should not pass in a window of less than 10 minutes. The system will try its best to accommodate smaller windows if the alarm is supposed to fire in the near future, but there are no guarantees and the app should expect any window smaller than 10 minutes to get elongated to 10 minutes.

See also:

Android reference for android.app.AlarmManager.setWindow.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

SetWindow(AlarmType, Int64, Int64, String, IExecutor, AlarmManager+IOnAlarmListener)

Direct callback version of setWindow(int,long,long,PendingIntent).

[Android.Runtime.Register("setWindow", "(IJJLjava/lang/String;Ljava/util/concurrent/Executor;Landroid/app/AlarmManager$OnAlarmListener;)V", "GetSetWindow_IJJLjava_lang_String_Ljava_util_concurrent_Executor_Landroid_app_AlarmManager_OnAlarmListener_Handler", ApiSince=34)]
public virtual void SetWindow(Android.App.AlarmType type, long windowStartMillis, long windowLengthMillis, string? tag, Java.Util.Concurrent.IExecutor executor, Android.App.AlarmManager.IOnAlarmListener listener);
[<Android.Runtime.Register("setWindow", "(IJJLjava/lang/String;Ljava/util/concurrent/Executor;Landroid/app/AlarmManager$OnAlarmListener;)V", "GetSetWindow_IJJLjava_lang_String_Ljava_util_concurrent_Executor_Landroid_app_AlarmManager_OnAlarmListener_Handler", ApiSince=34)>]
abstract member SetWindow : Android.App.AlarmType * int64 * int64 * string * Java.Util.Concurrent.IExecutor * Android.App.AlarmManager.IOnAlarmListener -> unit
override this.SetWindow : Android.App.AlarmType * int64 * int64 * string * Java.Util.Concurrent.IExecutor * Android.App.AlarmManager.IOnAlarmListener -> unit

Parameters

type
AlarmType

int: Value is one of the following: RTC_WAKEUP RTC ELAPSED_REALTIME_WAKEUP ELAPSED_REALTIME

windowStartMillis
Int64

long

windowLengthMillis
Int64

long

tag
String

String: This value may be null.

executor
IExecutor

Executor: This value cannot be null.

listener
AlarmManager.IOnAlarmListener

AlarmManager.OnAlarmListener: This value cannot be null.

Attributes

Remarks

Direct callback version of setWindow(int,long,long,PendingIntent). Rather than supplying a PendingIntent to be sent when the alarm time is reached, this variant supplies an OnAlarmListener instance that will be invoked at that time. Listener based alarms may be canceled by the Android system whenever the calling process no longer has any components running, such as Activity, Service, or ContentProvider, so only use these APIs when you do not need to receive alarms after the current component finishes, and also make sure to cancel(OnAlarmListener) them when it does. For example, if you use these APIs from an Activity, make sure to cancel the respective alarms when the activity finishes. If you need to receive the alarm even after that, use the PendingIntent based APIs. The OnAlarmListener onAlarm() method will be invoked via the specified target Executor. Note: Starting with API Build.VERSION_CODES.S, apps should not pass in a window of less than 10 minutes. The system will try its best to accommodate smaller windows if the alarm is supposed to fire in the near future, but there are no guarantees and the app should expect any window smaller than 10 minutes to get elongated to 10 minutes.

See also:

Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Last updated 2026-08-03 UTC.

Android reference for android.app.AlarmManager.setWindow.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to