Język

AlarmManager.SetExactAndAllowWhileIdle Method

Definition

Overloads

Name Description
SetExactAndAllowWhileIdle(AlarmType, Int64, PendingIntent)

Like #setExact(int, long, PendingIntent), but this alarm will be allowed to execute even when the system is in low-power idle modes.

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

Like setExact(int,long,String,OnAlarmListener,Handler), but this alarm will be allowed to execute even when the system is in low-power idle modes.

SetExactAndAllowWhileIdle(AlarmType, Int64, PendingIntent)

Like #setExact(int, long, PendingIntent), but this alarm will be allowed to execute even when the system is in low-power idle modes.

[Android.Runtime.Register("setExactAndAllowWhileIdle", "(IJLandroid/app/PendingIntent;)V", "GetSetExactAndAllowWhileIdle_IJLandroid_app_PendingIntent_Handler", ApiSince=23)]
[Android.Runtime.RequiresPermission("android.permission.SCHEDULE_EXACT_ALARM")]
public virtual void SetExactAndAllowWhileIdle(Android.App.AlarmType type, long triggerAtMillis, Android.App.PendingIntent operation);
[<Android.Runtime.Register("setExactAndAllowWhileIdle", "(IJLandroid/app/PendingIntent;)V", "GetSetExactAndAllowWhileIdle_IJLandroid_app_PendingIntent_Handler", ApiSince=23)>]
[<Android.Runtime.RequiresPermission("android.permission.SCHEDULE_EXACT_ALARM")>]
abstract member SetExactAndAllowWhileIdle : Android.App.AlarmType * int64 * Android.App.PendingIntent -> unit
override this.SetExactAndAllowWhileIdle : Android.App.AlarmType * int64 * Android.App.PendingIntent -> unit

Parameters

type
AlarmType

type of alarm.

triggerAtMillis
Int64

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 PendingIntent#getBroadcast IntentSender.getBroadcast().

Attributes

Remarks

Like setExact(int,long,PendingIntent), but this alarm will be allowed to execute even when the system is in low-power idle modes. If you don't need exact scheduling of the alarm but still need to execute while idle, consider using setAndAllowWhileIdle(int, long, PendingIntent). 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. Note that the OS will allow itself more flexibility for scheduling these alarms than regular exact alarms, since the application has opted into this behavior. When the device is idle it may take even more liberties with scheduling in order to optimize for battery life.

Note: Starting with Build.VERSION_CODES.S, apps targeting SDK level 31 or higher need to request the 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. Alarms scheduled via this API will be allowed to start a foreground service even if the app is in the background.

See also:

Android reference for android.app.AlarmManager.setExactAndAllowWhileIdle.

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

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

Like setExact(int,long,String,OnAlarmListener,Handler), but this alarm will be allowed to execute even when the system is in low-power idle modes.

[Android.Runtime.Register("setExactAndAllowWhileIdle", "(IJLjava/lang/String;Ljava/util/concurrent/Executor;Landroid/app/AlarmManager$OnAlarmListener;)V", "GetSetExactAndAllowWhileIdle_IJLjava_lang_String_Ljava_util_concurrent_Executor_Landroid_app_AlarmManager_OnAlarmListener_Handler", ApiSince=37)]
public virtual void SetExactAndAllowWhileIdle(Android.App.AlarmType type, long triggerAtMillis, string tag, Java.Util.Concurrent.IExecutor executor, Android.App.AlarmManager.IOnAlarmListener listener);
[<Android.Runtime.Register("setExactAndAllowWhileIdle", "(IJLjava/lang/String;Ljava/util/concurrent/Executor;Landroid/app/AlarmManager$OnAlarmListener;)V", "GetSetExactAndAllowWhileIdle_IJLjava_lang_String_Ljava_util_concurrent_Executor_Landroid_app_AlarmManager_OnAlarmListener_Handler", ApiSince=37)>]
abstract member SetExactAndAllowWhileIdle : Android.App.AlarmType * int64 * string * Java.Util.Concurrent.IExecutor * Android.App.AlarmManager.IOnAlarmListener -> unit
override this.SetExactAndAllowWhileIdle : Android.App.AlarmType * int64 * string * Java.Util.Concurrent.IExecutor * Android.App.AlarmManager.IOnAlarmListener -> unit

Parameters

type
AlarmType

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

triggerAtMillis
Int64

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

tag
String

A string tag used to identify this alarm in logs and battery-attribution. This value cannot be null.

executor
IExecutor

The Executor on which to execute the listener's onAlarm() callback. This value cannot be null.

listener
AlarmManager.IOnAlarmListener

OnAlarmListener instance whose onAlarm() method will be called when the alarm time is reached. This value cannot be null.

Attributes

Remarks

Like setExact(int,long,String,OnAlarmListener,Handler), but this alarm will be allowed to execute even when the system is in low-power idle modes.

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.

Android reference for android.app.AlarmManager.setExactAndAllowWhileIdle.

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