Android: After a long sleep, AlarmManager stops updating - android

I'm using the following code to schedule a service once a minute:
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC, calendar.getTimeInMillis(), 60 * 1000, createFrequentUpdateIntent(context));
Everything works OK for some time, but after a few hours I stop receiving the update intent. I wake the phone up, wait a few minutes and nothing happens.
How can I solve this?

Related

Alarm Manager not working properly for given interval

I need to call alarm Manger for the interval of every 2 minutes,I have implemented below code :-
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, downloader, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + (2 * 1000*60),(2 * 1000*60), pendingIntent);
I am facing problem that it is not working on exact interval of 2 minutes,means it is getting fired sometimes before one minute some time after 2 minutes
but i need to generate logs of this with the exact interval of 2 minutes,wheather phone is on wake up mode or in sleep mode.
I am using api level 23 for this functionality. please help....

Android - on sansung j5 Pending intent call does not work properly

I wrote a service to call pending intent after 1 minute
code:
AlarmManager alarms = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarms.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),
60 * 1000, pendingIntent);
this code works properly on all devices except samsung j5.Where it calls service after 5 minutes.
Please let me know what could be the possible reason for this issue.

Daily alarm not triggered after 2 or 3 days

I want to trigger a daily alarm in my application. I can see the alarm being triggered daily at the correct time for 2 or 3 days but it does not trigger after that. For example if I set alarm to trigger at 08:00 AM, it will trigger at 8 AM daily for 2 or 3 days and after that there is no alarm triggered. There is no app crashing or anything, it simply does not trigger. I have a BroadcastReceiver registered (in AndroidManifest.xml) for this alarm and i can see logs being printed daily at the correct time but only for 2 or 3 days. After that there is no activity and the app just seems to die down.
Please find my code below :
final AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
final long intervalDay = 60*60*24*1000L;
final long alarmTime = calendar.getTimeInMillis();
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, alarmTime, intervalDay, pendingIntent);
I have also used alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, alarmTime, AlarmManager.INTERVAL_DAY, pendingIntent); but it did not make any difference (didnt expect it to make any though).
I do not want to use alarmManager.setInexactRepeating() as it does not trigger the alarm at exact time but there is slight delay.
Any help appreciated !!
Thanks.
That's because android cannot hold the alarm content for more than 2-3 days. Though there is no sure shot solution that i know.
I fixed it by cancelling and resetting alarm everytime alarm is triggered.
Something like this.
Instead of using setRepeat use set or setExact to trigger for once:
if(android.os.Build.VERSION.SDK_INT<Build.VERSION_CODES.KITKAT) {
alarmManager.set(AlarmManager.RTC_WAKEUP, alarmtime, pendingIntent);
} else {
alarmManager.setExact(AlarmManager.RTC_WAKEUP, alarmtime, pendingIntent);
}
Then in onRecieve() method of your alarmReciever after performing your task, reset the alarm again for next followed by cancelling all pending intents:
PendingIntent pendingIntent = PendingIntent.getBroadcast(context.getApplicationContext(), reminderModal.get_remindID(), intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) context.getApplicationContext().getSystemService(Context.ALARM_SERVICE);
alarmManager.cancel(pendingIntent);
pendingIntent.cancel();
Hope it helps.

Alarmmanager schedule the same pending intent to fire twice at the same time

My intent was supposed to be fired once every 30 seconds. since I'm using Android 5.0 for testing, the alarm api schedules and fires it with other alarm events every 20-40s.
pendingIntent= PendingIntent.getBroadcast(getApplicationContext(), 0, i, PendingIntent.FLAG_CANCEL_CURRENT);
alarmManager = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 0, 30000, pendingIntent);
sometimes the 2 of the same pending intent is scheduled to fire at the same time. This happens once in about 5 minutes. How can I avoid this?

Android AlarmManager probleme

I have a problem with my alarm manager.
I want execute my code every 2 minutes so i made an alarm like this :
AlarmManager manager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
manager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 120000, pendingIntent);
But when i test this, my pendingIntent is executed every minutes.
If i start the application at 15:05:30
the first start of my pending intent is at : 15:06:00
and after every minutes.
I want to start when i start the application and after every 2 minutes.
Thx for your answers :)

Categories

Resources