Android Alarmmanager Send Notification Every Time App Starts Instead Of Only Once
My app use an AlarmManager that start a BroadcastReceiver. The BroadcastReceiver generate a reminder notification to the user. This is the MainActivity that start the Alarm public
Solution 1:
The issue is you are setting the time to current day. So if you are opening your app after 14:00, your alarm manager will immediately fire.
You need to check whether the time is over 14:00 for the current day, if yes you need to change the date to the next day:
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
int curHr = calendar.get(Calendar.HOUR_OF_DAY);
// Checking whether current hour is over 14if (curHr >= 14)
{
// Since current hour is over 14, setting the date to the next day
calendar.add(Calendar.DATE, 1);
}
calendar.set(Calendar.HOUR_OF_DAY, 14);
// Schedule alarm manager
Baca Juga
- No Sound When The Activity Starts From Lock Screen
- Setrepeating() Of Alarmmanager Repeats After 1 Minute No Matter What The Time Is Set (5 Seconds In This Case, Api 18+)
- How To Draw Brushes Or Shape Using Path When Moving Finger Fast In Andorid Canvas (generate Missing Point When User Move Finger Fast)
Post a Comment for "Android Alarmmanager Send Notification Every Time App Starts Instead Of Only Once"