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
15
votes
3 answers

Difference between AlarmManager and ScheduledExecutorService

Besides setting and exact time (i.e. midnight) versus setting a delay (i.e. 24 hours), what's the difference between using AlarmManager and ScheduledExecutorService to run a task periodically? In my case, I need to run a little bit of code to check…
Computerish
  • 9,590
  • 7
  • 38
  • 49
15
votes
4 answers

Android Oreo killing background services and clears pending alarms, scheduled jobs after entering doze mode

My app has a background service running that gets users current location and update it to a server every five minutes. To run this location update process continuously, I use alarm manager to set its next execution time from the service itself.…
k9yosh
  • 858
  • 1
  • 11
  • 31
15
votes
3 answers

How to protect background service/alarms to be kill in newly launched devices in customized OS like oppo - coloros, vivo-funtouch os, Xiomi-MIUI os?

I have a WakefulBroadcastReceiver with IntentService, every half hour alarm called and doing some stuff. I have already handle doze mode with setExactAndAllowWhileIdle() method. Some new smart phones with customized os recently launched in market…
Himanshu
  • 861
  • 10
  • 25
14
votes
1 answer

What happens when I start an alarm twice?

I'm Jumping trough hoops (well, it's not that complicated ofcourse) to avoid starting an alarm twice. The basic code goes like this: AlarmManager mgr=(AlarmManager)getSystemService(Context.ALARM_SERVICE); Intent i=new Intent(this,…
Nanne
  • 64,065
  • 16
  • 119
  • 163
14
votes
3 answers

Creating A Digital Clock Widget With A Custom Font

I'm trying to create a digital clock widget with a custom font. And this has proven to be the biggest challenge of my Android experience. (Thought it would be as simple as tc.setTypeFace("whatever") and be done with it) The best way seems to be…
14
votes
3 answers

AlarmManager and BroadcastReceiver instead of Service - is that bad ? (Timeout)

BACKGROUND INFO: I need to update some data from the web, about every hour or so, even when my app is closed. The update of the data itself takes about 40 seconds to 1 minute. It is then saved as a Serializable to a file. This file is read when my…
Hubert
  • 16,012
  • 18
  • 45
  • 51
14
votes
2 answers

SharedPreferences in BroadcastReceiver seems to not update?

I have a Activity which updates a string in the SharedPreferences. SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences.Editor editor = settings.edit(); editor.putString("username",…
13
votes
3 answers

AlarmManager, BroadcastReceiver and Service not working

I'm refactoring some code so that my app will pull data from a website once a day at a given time. From my research, it seems like AlarmManager is the most appropriate approach. The tutorial I have been following is:…
pyko
  • 3,399
  • 5
  • 26
  • 31
13
votes
3 answers

setExactAndAllowWhileIdle() for alarmmanager is not working properly

I am developing an app which needs to perform particular action on the exact time which user has set. For this i am using setExactAndAllowWhileIdle() method because this documentation says that android devices having android 6.0 or above has doze…
Jaydip Kalkani
  • 2,493
  • 6
  • 24
  • 56
13
votes
4 answers

Develop Alarm Application

I'd like develop an Alarm Application. The application should work like this: launch it the activity show me the time I can set the alarm I can close the application when the alarm time comes , it starts an activity (even if the device is…
vittochan
  • 635
  • 1
  • 7
  • 18
13
votes
3 answers

Repeating Alarm for specific days of week android

In my application I have a functionality to trigger alarm in 4 senerios: Only once for a user chosen date and time Daily for chosen time Weekly according to chosen date and time User chosen custom days of the week I successfully implement the…
Dhruvil Patel
  • 2,910
  • 2
  • 22
  • 39
13
votes
3 answers

AlarmManager fires alarms in the past immediately before BroadcastReceiver can reschedule it

I have a BroadcastReceiver which reschedules alarms on events such as booting and time change. But when the time is past the trigger time of the alarm (For example, when the user manually changes the time from the settings), AlarmManager fires the…
Piyush
  • 1,744
  • 1
  • 15
  • 28
13
votes
2 answers

Android Alarm Manager with broadcast receiver registered in code rather than manifest

I want to use an alarm to run some code at a certain time. I have successfully implemented an alarm with the broadcast receiver registered in the manifest but the way i understand it, this method uses a separate class for the broadcast receiver. I…
Shane
  • 249
  • 1
  • 3
  • 10
13
votes
3 answers

Why is my android alarm manager firing instantly?

I am following sample code for sending an update notification every 10'seconds. The code follows and it is in an UpdateService for an AppWidgetProvider. If I put a Thread.sleep(10*1000); I can see the expected behavior of my servicing loop. I…
mobibob
  • 8,670
  • 20
  • 82
  • 131
13
votes
4 answers

AlarmManager does not always execute BroadcastReceiver

So I've got a BroadcastReceiver and the AlarmManager. Let's say I create the Pending Intents like so: Intent i; i = new Intent(context, MyReceiver.class); i.setAction(MyReceiver.ACTION_1); i.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); pendingIntent1…
flxapps
  • 1,066
  • 1
  • 11
  • 24