You should register the receiver you use to catch the alarms in your manifest along with your other receivers. Then create your intent to launch the AlarmReceiver.
When you do it in code, as you are, it's unregistered in onPause
, so if your activity isn't in the foreground when the alarm fires, it's not going to catch it.
Manifest:
<receiver android:name="com.test.receiver.AlarmReceiver"
/>
Code:
private void setRecurringDailyAlarm(){
Calendar updateTime = Calendar.getInstance();
updateTime.setTimeInMillis(System.currentTimeMillis());
//daily alarm at midnight
updateTime.set(Calendar.HOUR_OF_DAY,00);
updateTime.set(Calendar.MINUTE,00);
updateTime.set(Calendar.SECOND,00);
Log.d(TAG, "Alarm time is: " + updateTime.getTime());
Intent myIntent = new Intent( this, AlarmReceiver.class );
PendingIntent recurringAlarm = PendingIntent.getBroadcast( MainActivity.this, ALARM_ID, myIntent, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager alarms = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
alarms.setRepeating(AlarmManager.RTC_WAKEUP, updateTime.getTimeInMillis(),
AlarmManager.INTERVAL_DAY, recurringAlarm);
}