I have asked this before and God knows I have tried everything suggested. I am trying to have a service get executed once a day at a given time daily. I was able to set the alarm and broadcasts. But for some reason when the alarm gets fired, say 13h30, it's gonna get fired thereon at several irregular intervals. The only thing that's working properly is having the alarm fire at the correct time first, however it will then fire throughout the day and it's driving me crazy. Please help.
PendingIntent reviewsPendingIntent = PendingIntent.getBroadcast(this,0,new Intent(this,ReviewReceiver.class),PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager)(this.getSystemService(Context.ALARM_SERVICE));
Calendar cur_cal = new GregorianCalendar();
cur_cal.setTimeInMillis(System.currentTimeMillis());
Random random = new Random();
int low = 7;
int high = 22;
int hour = random.nextInt(high - low) + low;
int minute = random.nextInt(60 - 10) + 10;
Calendar cal = new GregorianCalendar();
cal.set(Calendar.HOUR_OF_DAY, 13);
cal.set(Calendar.MINUTE,15);
cal.set(Calendar.SECOND,5);
cal.set(Calendar.MILLISECOND,0);
if(cal.getTimeInMillis() >= System.currentTimeMillis() ) {
Log.i(TAG,"Set today");
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), AlarmManager.INTERVAL_DAY, reviewsPendingIntent);
}else{
Log.i(TAG,"Set tomorrow");
cal.set(Calendar.DATE,1);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), AlarmManager.INTERVAL_DAY, reviewsPendingIntent);
}
N.B. I plan to use the random integers to set my alarm when I get this working properly.