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
You alarm is going off instantly because Android will fire off any alarms that are scheduled in the past.
Some of your alarms are getting scheduled in the past because the following code is not working as you expect. Sample code from your question:
if (calAlarm.before(calNow))
{
//if [it's] in the past increment
calAlarm.add(Calendar.DATE, 1);
}
In the above code you are only adding one day to your alarm if the alarm is in the past. So let's say you are running this code on Friday and you read an alarm for Monday. Your code will add one day to the date making it Tuesday, schedule that alarm. The alarm is in the past because Tuesday is still before Friday, so Android will fire off that alarm shortly after being scheduled.
It is unclear from your question what you wish to do with the reminders that are in the past. One possible solution is to schedule them 1 week into the future.
if(calAlarm.before(calNow))
{
// If it's in the past increment by one week.
calAlarm.add(Calendar.DATE, 7);
}