AlarmManager.SetExactAndAllowWhileIdle Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
int: type of alarm. Value is one of the following: RTC_WAKEUP RTC ELAPSED_REALTIME_WAKEUP ELAPSED_REALTIME
- triggerAtMillis
- Int64
long: time in milliseconds that the alarm should go off, using the appropriate clock (depending on the alarm type).
- operation
- PendingIntent
PendingIntent: Action to perform when the alarm goes off; typically comes from IntentSender.getBroadcast(). This value cannot be null.
- 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.