In Android studio i want my application send notification
to user if he do no use it.
Notification
is fire but always when i leave the activity and after 8:00
@Override
protected void onStop() {
super.onStop();
System.out.println("STARTED!");
Intent intent = new Intent(this, Alarm.class);
PendingIntent pendingIntent =
PendingIntent.getBroadcast(this.getApplicationContext(), 0, intent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, 8);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 1);
alarmManager.cancel(pendingIntent);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
}
The alarm fires once always when i leave the activity and the time is greater then 8:00;