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

Android O and background limits prevents simple alarm notification

My own app uses the exact same technique as shown by Google I/O app of 2016. see source I need to remind users at a very specific point in time - using a notification. For this, I use the AlarmManager to wake the device at the correct point in…
Zordid
  • 10,451
  • 11
  • 42
  • 58
17
votes
6 answers

onPostExecute not being called in AsyncTask (Handler runtime exception)

I have an AsyncTask that fetches some data and then updates the UI with this new data. It has been working fine for months, but I recently added a feature that displays a notification when there is new data. Now when my app is launched through the…
Computerish
  • 9,590
  • 7
  • 38
  • 49
17
votes
2 answers

AlarmManager fires alarms at wrong time

I managed everything all right to create a notification service used to fire a notification as a result of an alarm. Unfortunately, setting the alarm using AlarmManager doesn't work right. It fires several minutes later (not exactly hours, which…
Holger Jakobs
  • 984
  • 3
  • 11
  • 32
17
votes
2 answers

Alarm manager triggered immediately

Hi I am currently working with AlarmManager. I have written a code given below. As per code the AlarmManager should be triggered after 10 Sec, but here in my code the alarm manager triggers immediately. Please help. public class MainActivity…
Rida Shahid
  • 386
  • 7
  • 22
17
votes
3 answers

Start Android Service after every 5 minutes

I was searching over the internet for last 2 days but I couldn't find any tutorial helpful. I have created a service and I am sending a notification in status bar when the service starts. I want that service to stop after showing the notification…
Kashif Umair Liaqat
  • 1,064
  • 1
  • 18
  • 27
17
votes
4 answers

Android Intent to start Main activity of application

I am trying to start the main activity from inside a BroadcastReceiver. I dont want to supply the activity class name but to use the action and category for android to figure out the main activity. It doesnt seem to work. Sending Code: Intent…
Abhishek
  • 1,749
  • 9
  • 27
  • 39
16
votes
1 answer

passing intent extra to android broadcast receiver

I have created a AlarmReceiver class which is used as broadcast receiver for alarm. The issue is that I need to send some values from the class which is setting the alarm to the broadcast receiver class. setAlarmManager.java Intent i = new…
16
votes
4 answers

How to set Alarm in Android programmatically?

Following is my code can Any body please tell me why it is not working .I have learned it from this tutorial. But it is not working any help will be appreciable. My code is import java.util.Calendar; import android.app.Activity; import…
Nitin
  • 1,966
  • 4
  • 22
  • 53
16
votes
1 answer

Stop the setrepeat of Android alarmmanager

I have created the alarm as shown below Intent intent = new Intent(this, Areceiver.class); PendingIntent sender = PendingIntent.getBroadcast(this, 1234567, intent, 0); AlarmManager am = (AlarmManager)…
sankara rao bhatta
  • 649
  • 5
  • 9
  • 13
16
votes
2 answers

How to Set Recurring AlarmManager to execute code daily

I am currently trying to write alarm manager that will make an alarm go off within a specified period of time, daily. First I check to see if the user has had an alarm set for that for that day: if ((User.getReminderTime(Home.this) > 0) …
ninjasense
  • 13,756
  • 19
  • 75
  • 92
16
votes
2 answers

FLAG_CANCEL_CURRENT or FLAG_UPDATE_CURRENT

My app sets a repeating alarm on user interaction, it might change the interval time set for the broadcast with Alarm Manager. There is not much in the way of extras. Is the update or cancel flag better in this case? Thanks
Dory
  • 7,462
  • 7
  • 33
  • 55
16
votes
4 answers

Should I use AlarmManager or Handler?

I'm writing an app that constantly polls the device's sensors and every so often should write down some statistics to a file. This could be as fast as once a second or as slow once a minute. Should I use Handler's postDelayed()method or just…
Moises Jimenez
  • 1,962
  • 3
  • 21
  • 43
16
votes
1 answer

Send data to the alarm manager broadcast receiver

I am missing something here and I hope someone can help me out. I am setting up an alarm using the following: AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); Intent broadcast_intent = new Intent(this,…
Snake
  • 14,228
  • 27
  • 117
  • 250
15
votes
1 answer

How to set more than one alarms at a time in android?

I am making a small app where I have to set alarm from array but only one alarm is set and working at a time which is at last position of array why it is behaving like this following is my code AlarmManager[] alarmManager=new AlarmManager[24]; …
Nitin
  • 1,966
  • 4
  • 22
  • 53
15
votes
8 answers

How do you start an Activity with AlarmManager in Android?

I've poured through a dozen tutorials and forum answers about this problem, but still haven't been able to get some working code together. I'll try to keep the question straightforward: How do you use AlarmManager (in the Android API) to start an…
BenLambell
  • 354
  • 1
  • 3
  • 9