Dil

AlarmManager.Set Method

Definition

Overloads

Name Description
Set(AlarmType, Int64, String, AlarmManager+IOnAlarmListener, Handler)

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

Set(AlarmType, Int64, PendingIntent)

Schedule an alarm.

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

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

[Android.Runtime.Register("set", "(IJLjava/lang/String;Landroid/app/AlarmManager$OnAlarmListener;Landroid/os/Handler;)V", "GetSet_IJLjava_lang_String_Landroid_app_AlarmManager_OnAlarmListener_Landroid_os_Handler_Handler", ApiSince=24)]
public virtual void Set(Android.App.AlarmType type, long triggerAtMillis, string? tag, Android.App.AlarmManager.IOnAlarmListener listener, Android.OS.Handler? targetHandler);
[<Android.Runtime.Register("set", "(IJLjava/lang/String;Landroid/app/AlarmManager$OnAlarmListener;Landroid/os/Handler;)V", "GetSet_IJLjava_lang_String_Landroid_app_AlarmManager_OnAlarmListener_Landroid_os_Handler_Handler", ApiSince=24)>]
abstract member Set : Android.App.AlarmType * int64 * string * Android.App.AlarmManager.IOnAlarmListener * Android.OS.Handler -> unit
override this.Set : Android.App.AlarmType * int64 * string * Android.App.AlarmManager.IOnAlarmListener * Android.OS.Handler -> 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).

tag
String

String: string describing the alarm, used for logging and battery-use attribution. This value may be null.

listener
AlarmManager.IOnAlarmListener

AlarmManager.OnAlarmListener: OnAlarmListener instance whose 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: Handler on which to execute the listener's onAlarm() callback, or null to run that callback on the main looper.

Attributes

Remarks

Direct callback version of set(int,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's 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.

Android reference for android.app.AlarmManager.set.

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

Set(AlarmType, Int64, PendingIntent)

Schedule an alarm.

[Android.Runtime.Register("set", "(IJLandroid/app/PendingIntent;)V", "GetSet_IJLandroid_app_PendingIntent_Handler")]
public virtual void Set(Android.App.AlarmType type, long triggerAtMillis, Android.App.PendingIntent operation);
[<Android.Runtime.Register("set", "(IJLandroid/app/PendingIntent;)V", "GetSet_IJLandroid_app_PendingIntent_Handler")>]
abstract member Set : Android.App.AlarmType * int64 * Android.App.PendingIntent -> unit
override this.Set : 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

Schedule an alarm. Note: for timing operations (ticks, timeouts, etc) it is easier and much more efficient to use 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), 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) 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 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,PendingIntent) and setExact(int,long,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.

See also:

Android reference for android.app.AlarmManager.set.

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