Partager via


AlarmManager.Set Method

Definition

Overloads

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

Schedule an alarm.

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

[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
triggerAtMillis
Int64
tag
String
targetHandler
Handler
Attributes

Remarks

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

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

Schedule an alarm. <b>Note: for timing operations (ticks, timeouts, etc) it is easier and much more efficient to use android.os.Handler.</b> 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 android.content.Context#registerReceiver or through the &lt;receiver&gt; tag in an AndroidManifest.xml file.

Alarm intents are delivered with a data extra of type int called Intent#EXTRA_ALARM_COUNT 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.

<div class="note">

<b>Note:</b> 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' <em>actual</em> delivery ordering may not match the order of their <em>requested</em> 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. </div>

Java documentation for android.app.AlarmManager.set(int, long, android.app.PendingIntent).

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.

See also

  • Handler
  • <xref:Android.App.AlarmManager.SetExact(Android.App.AlarmType%2c+System.Int64%2c+System.Int64)>
  • <xref:Android.App.AlarmManager.SetRepeating(Android.App.AlarmType%2c+System.Int64%2c+System.Int64%2c+System.Int64)>
  • <xref:Android.App.AlarmManager.SetWindow(Android.App.AlarmType%2c+System.Int64%2c+System.Int64%2c+System.Int64)>
  • Cancel(PendingIntent)
  • SendBroadcast(Intent)
  • <xref:Android.Content.Context.RegisterReceiver(Android.Content.BroadcastReceiver%2c+Android.Content.IntentFilter)>
  • FilterEquals(Intent)

Applies to