Jayakrishnan Salim Jayakrishnan Salim - 2 months ago 15x
Android Question

Alarm manager not triggering everyday

In my project I have a requirement to schedule a task to show notification at a particular time everyday. If I set it for some time today, its triggering and all is going as expected but if the schedule time is tomorrow, its not triggering. Below is my code to set the alarm manager.

public void setMorningRepeatingTask(Context context, int hour, int minutes) {
alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, AlarmBroadcastReceiver.class);
alarmIntent = PendingIntent.getBroadcast(context, Constants.MORNING_ALARM_UNIQUE_ID, intent,
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, hour);
calendar.set(Calendar.MINUTE, minutes);
calendar.add(Calendar.DATE, 1);
alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
AlarmManager.INTERVAL_DAY, alarmIntent);
FileLogger.writeToFile("Alarm Set", "Morning repeating Alarm Set");

public static boolean checkIfTheTimeHasPassed(long timeInMillis) {
long nowTime = new Date().getTime();
return nowTime > timeInMillis;

Kindly help.


Finally I found a solution to the issue I am facing. I used alarmMgr.set() method instead of alarmMgr.setRepeating() and when the alarm rings off I set another alarm for the next day. In this way, it will repeat day after day. :)

I still would like to know whats wrong with alarmMgr.setRepeating() method. So, if anyone has any idea, please post the solution.