I'm trying to set an alarm for a notification using AlarmManager. The alarms are set when user selects a list item, so I'm trying to set a separate alarm every time (with unique ID passed into the pendingIntent) a list item is selected.
The code used to set the alarm:
public static void setAlarm(Context context, Movie movie, Schedule schedule){
Intent arg = new Intent(context, NotifyService.class);
arg.putExtra(NotificationHelper.fetch_schedule_id, schedule.getId());
arg.putExtra(NotificationHelper.fetch_movie_id, movie.getId());
PendingIntent pendingIntent = PendingIntent.getService(context.getApplicationContext(), (int) schedule.getId(), arg, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
am.setExact(AlarmManager.RTC_WAKEUP, schedule.getStart().getTime(), pendingIntent);
else
am.set(AlarmManager.RTC_WAKEUP, schedule.getStart().getTime(), pendingIntent);
}
The issue I'm dealing with is that the call to set(or setExact) method is not being executed at times. It does work half of the times, but in specific cases like, when user taps on two or more list items, one after the another in less than a second, then only the first call is executed and rest of the calls are just ignored.
Also, since set/setexact methods return void there's no way I can debug if the method was called and the alarm was set. For now I have to check the adb shell dumpsys alarm everytime.
So if someone can tell me how to schedule an alarm such that it is triggered every time, no matter how frequently the method is called or even guide me in the right direction, it'd be a great help. :)