Questions tagged [alarmmanager]

Android class providing access to the system alarm services.

AlarmManager class provides access to the system alarm services. These allow you to schedule your application to be run at some point in the future. When an alarm goes off, the Intent that had been registered for it is broadcast by the system, automatically starting the target application if it is not already running. Registered alarms are retained while the device is asleep (and can optionally wake the device up if they go off during that time), but will be cleared if it is turned off and rebooted.

The AlarmManager holds a CPU wake lock as long as the alarm receiver's onReceive() method is executing. This guarantees that the phone will not sleep until you have finished handling the broadcast. Once onReceive() returns, the AlarmManager releases this wake lock. This means that the phone will in some cases sleep as soon as your onReceive() method completes. If your alarm receiver called Context.startService(), it is possible that the phone will sleep before the requested service is launched. To prevent this, your BroadcastReceiver and Service will need to implement a separate wake lock policy to ensure that the phone continues running until the service becomes available.

AlarmManager reference

4606 questions
392
votes
10 answers

Alarm Manager Example

I want to implement a schedule function in my project. So I Googled for an Alarm manager program but I can`t find any examples. Can anyone help me with a basic alarm manager program?
Rajamohan Sugumaran
  • 4,439
  • 4
  • 22
  • 19
262
votes
13 answers

How to check if AlarmManager already has an alarm set?

When my app starts, I want it to check if a particular alarm (registered via AlarmManager) is already set and running. Results from google seem to indicate that there is no way to do this. Is this still correct? I need to do this check in order to…
ron
  • 5,219
  • 8
  • 39
  • 44
217
votes
11 answers

Calling startActivity() from outside of an Activity?

I'm using an AlarmManager to trigger an intent that broadcasts a signal. The following is my code: AlarmManager mgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(this, Wakeup.class); try { PendingIntent pi =…
Tom G
  • 2,595
  • 5
  • 20
  • 16
140
votes
5 answers

What's "requestCode" used for on PendingIntent?

Background: I'm using PendingIntent for alarms via AlarmManager. The problem: At first I thought that in order to cancel previous ones, I must provide the exact requestCode that I've used before to start the alarm. But then I've found out I was…
android developer
  • 114,585
  • 152
  • 739
  • 1,270
94
votes
6 answers

Android: How to use AlarmManager

I need to trigger a block of code after 20 minutes from the AlarmManager being set. Can someone show me sample code on how to use an AlarmManager in ِAndroid? I have been playing around with some code for a few days and it just won't work.
Tom
  • 7,316
  • 9
  • 35
  • 35
93
votes
14 answers

AlarmManager not working in several devices

My app uses AlarmManager and it has been working since 4 years ago. But I noticed it started failing in some devices. I'm pretty sure code is right (I'm using WakefulBroadcastReceiver, and setExactAndAllowWhileIdle for devices with Doze) because…
Sergio Viudes
  • 2,714
  • 5
  • 26
  • 44
91
votes
5 answers

Android AlarmManager - RTC_WAKEUP vs ELAPSED_REALTIME_WAKEUP

Can someone explain to me the difference between AlarmManager.RTC_WAKEUP and AlarmManager.ELAPSED_REALTIME_WAKEUP? I have read the documentation but still don't really understand the implication of using one over the other. Example code: …
Camille Sévigny
  • 5,104
  • 4
  • 38
  • 61
86
votes
3 answers

How to read "adb shell dumpsys alarm" output

I'm struggling with setting an alarm properly, and understanding the mechanism of cancelling and rescheduling alarms. I have found, that there is an adb command to retrieve all alarms scheduled on device, but I haven't found a documentation,…
Eugene Shtoka
  • 1,117
  • 1
  • 8
  • 14
75
votes
5 answers

Android: Get all PendingIntents set with AlarmManager

I'm setting an alarm like this: alarmManager.set(AlarmManager.RTC_WAKEUP, alarmTime, pendingEvent); I'm interested in removing all the alarms that where previously set, clearing them. Is there a way for me to do that or to get all the alarms that…
bluediapente
  • 3,946
  • 5
  • 32
  • 38
63
votes
7 answers

How to set multiple alarms using alarm manager in android

I'm building an alarm application. I have successfully implemented basic alarm functions. Calendar calendar = Calendar.getInstance(); calendar.set(calendar.HOUR_OF_DAY, sHour); calendar.set(calendar.MINUTE, sMin); calendar.set(calendar.SECOND,…
Hassy31
  • 2,793
  • 3
  • 21
  • 37
57
votes
3 answers

does Alarm Manager persist even after reboot?

I am really new to android, I have been researching about alarms. I want to alarm if there is a birthday on that day. I've have used alarm manager. I was confused because i have read that it clears after reboot. I don't have an android phone so I'm…
Xelamae
  • 603
  • 1
  • 5
  • 8
54
votes
1 answer

JobScheduler: controlling delay from constraints being met to job being run

I'm using JobScheduler to schedule jobs. Mainly I'm using it for the .setRequiredNetworkType() method, which allows you to specify that you only want the job to be scheduled when a network connection (or more specifically an unmetered connection)…
drmrbrewer
  • 11,491
  • 21
  • 85
  • 181
54
votes
2 answers

How to make Alarm Manager work when Android 6.0 in Doze mode?

I am a developer of two alarm clock apps on Google Play. I am trying to get them to work with Android 6.0. However, Doze mode makes it so they do not ring. I put them on the white list, I put a foreground notification icon up, I'm not sure what…
user1908060
  • 683
  • 1
  • 6
  • 8
53
votes
7 answers

Android: keeping a background service alive (preventing process death)

I have a service that is defined as: public class SleepAccelerometerService extends Service implements SensorEventListener Essentially, I am making an app that monitors accelerometer activity for various reasons while the user sleeps with his or…
Jon Willis
  • 6,993
  • 4
  • 43
  • 51
53
votes
4 answers

setExactAndAllowWhileIdle - is not exact as of developer reference

AlarmManager on API19 has the method setExact() to set an exact alarm. Exact means --> If I set an alarm to 2:01 pm it will be triggered at 2:01 pm On API 23 - Marhsmwallow (6.0) there is a new method setExactAndAllowWhileIdle(), but as of the…
chrisonline
  • 6,949
  • 11
  • 42
  • 62
1
2 3
99 100