I am working on a Reminder that sends notification on fixed time to the user.
The alarm is getting off instantly ...
I tried most of the suggestions over s
Got hit by same issue and stumbled upon this question while finding the solution. When setting the alarm, You just need to place a check that your alarm date should not be before current date.
public static void setReminder(Context context,Class> cls,long milliseconds, int event_id,String eventName)
{
Calendar calendar = Calendar.getInstance();
Calendar notificationcalendar = Calendar.getInstance();
notificationcalendar.setTimeInMillis(milliseconds);
if(!notificationcalendar.before(calendar)) { // **just add this check**
ComponentName receiver = new ComponentName(context, cls);
PackageManager pm = context.getPackageManager();
pm.setComponentEnabledSetting(receiver,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
Intent intent1 = new Intent(context, cls);
intent1.putExtra("eventName", eventName);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, event_id, intent1, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager) context.getSystemService(ALARM_SERVICE);
am.setInexactRepeating(AlarmManager.RTC_WAKEUP, notificationcalendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
}
}