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
53
votes
2 answers

Android cannot pass intent extras though AlarmManager

I am trying to put an extra message in my intent to pass to AlarmManager to be triggered at a later time. My onReceive triggers correctly but extras.getString() returns null Setup: public PendingIntent getPendingIntent(int uniqueRequestCode, String…
47
votes
2 answers

Should I use PendingIntent.getService() or getBroadcast with AlarmManager?

My app needs to grab some data from the web at a specific time each day. So I use an AlarmManager to schedule the task and that works ok. But when looking at various examples there seems to be two ways to deal with the AlarmManager when it comes to…
marlar
  • 3,858
  • 6
  • 37
  • 60
47
votes
7 answers

Job Scheduler vs Background Service

I have an app which has a feature A which should run in background every minute. Feature A is that the app should connect to a database, read some data then get the current location of the device and based on them check a condition, if the condition…
46
votes
1 answer

WorkManager vs AlarmManager, what to use depending on the case

I have to perform this use case (not code , just the right usage) The use case : I need to fetch some data from the network everyday at 00:30 . These data provide me some specific times , and one of them is around 4:30 (changes everyday by +1 minute…
coroutineDispatcher
  • 7,718
  • 6
  • 30
  • 58
43
votes
7 answers

How to set an alarm to be scheduled at an exact time after all the newest restrictions on Android?

Note: I tried various solutions that are written about here on StackOverflow (example here). Please do not close this without checking if your solution from what you've found works using the test I've written below. Background There is a requirement…
android developer
  • 114,585
  • 152
  • 739
  • 1,270
38
votes
6 answers

java.lang.SecurityException: !@Too many alarms (500) registered from pid 10790 uid 10206

I'm getting this error at the time of Schedule alarm using Alarm Manager am.setExact(AlarmManager.RTC_WAKEUP, timeMillis, pendingIntent); Error is as follow java.lang.SecurityException: !@Too many alarms (500) registered from pid 10790 uid…
Manpreet Patil
  • 709
  • 1
  • 6
  • 13
36
votes
5 answers

Need code example on how to run an Android service forever in the background even when device sleeping, like Whatsapp?

I have tried various ways to achieve this, but my service eventually gets killed. I want to use AlarmManager to trigger a class every one hour. Even if the device is sleeping, it should sent a flashing LED alert, vibration or sound. In any case, it…
zeeshan
  • 4,913
  • 1
  • 49
  • 58
33
votes
5 answers

Difference between setRepeating and setInexactRepeating of AlarmManager

What are the parameters of the following: alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_FIFTEEN_MINUTES, alarmIntent); And of the following:…
User3
  • 2,465
  • 8
  • 41
  • 84
32
votes
5 answers

Android AlarmManager not working on some devices when the app is closed

I am trying to run IntentService as such from AlarmManager setRepeating() for every half an hour. I want to send a to broadcast, from broad cast to intent service. In the service, some functionality will be done. But, initially the AlarmManager in…
user2601701
  • 347
  • 1
  • 3
  • 6
32
votes
4 answers

Is there any way to check if an alarm is already set?

I am stuck. When my application starts I want to check if an alarm is alive that I previously set. If not then I want to set it. I referred to this solution. I am trying to match the intent like this: Intent intent = new Intent(); …
NullPointerException
  • 3,978
  • 4
  • 34
  • 52
29
votes
6 answers

Android AlarmManager setExact() is not exact

I need to plan sheduled task every 10 minutes. As in Lollipop and higher version setRepeating() is inexact, I use setExact() and (on alarm firing) I set new exact alarm in 10 minutes. private void setAlarm(long triggerTime, PendingIntent…
Goltsev Eugene
  • 3,325
  • 6
  • 25
  • 48
29
votes
6 answers

Using Alarmmanager to start a service at specific time

I have searched a lot of places but couldnt find a clean sequential explanation of how to start a service (or if thats not possible then an activity) at a specific time daily using the AlarmManager?? I want to register several such alarms and…
JaVadid
  • 7,107
  • 13
  • 42
  • 54
28
votes
3 answers

android AlarmManager not waking phone up

I want an activity to be displayed at a certain time. For this, I am using AlarmManager. It works fine when the device is awake, but it doesn't wake it up if it's asleep. My code for setting the alarm: Calendar alarmTime =…
Gabriel
  • 2,054
  • 4
  • 26
  • 34
28
votes
7 answers

Android alarm is cancelled after closing the application

I have a problem with AlarmManager, I set the code for scheduling a repeating alarm and after I run the application, the alarm runs fine. Even if I click on Home button (and the application is paused), the alarm still runs on its interval. The…
Allan Denot
  • 293
  • 1
  • 3
  • 8
28
votes
2 answers

AlarmManager Android Every Day

I'm trying to make a Schedule. It should run every day at 1pm or 2pm... At the moment I can only make it run Every 10Sec or 10min... Intent myIntent = new Intent(AndroidAlarmService.this, MyAlarmService.class); pendingIntent =…
Paul
  • 321
  • 1
  • 5
  • 8