In my application, I have set up many alarm notifications. They are all at different times, but at the same time. And I set it on / off using the toggle button.
Now the problem is that if I install it, then it gives me a notification of the previous of the current date. it appears only immediately, and then all alarm notifications work fine.
Suppose if I set the alarm to 12,14,16, then I set the date to 15 on my device and on the toggle button, then it gives me a notification of 14 at that time. And then everything goes well.
So, is this logically correct or is there some kind of problem in my code?
Should it be or not?
Please see below code that I set for alarm notification:
public void startTwoMonthAlarmNotification() {
AM_2M_GST_1 = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
Intent in1 = new Intent(this, AlarmReceiverNotificationForTwoMonth.class);
in1.putExtra("MyMessage","Your 2 Monthly GST return is DUE on 20th June 2011.");
PI_2M_GST_1 = PendingIntent.getBroadcast(this, 0, in1, PendingIntent.FLAG_UPDATE_CURRENT);
Calendar calendar_GST_18_June_2011 = Calendar.getInstance();
calendar_GST_18_June_2011.setTimeInMillis(System.currentTimeMillis());
calendar_GST_18_June_2011.set(2011, 5, 18, mHour, mMinute, 0);
AM_2M_GST_1.set(AlarmManager.RTC_WAKEUP, calendar_GST_18_June_2011.getTimeInMillis(), PI_2M_GST_1);
AM_2M_GST_2 = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
Intent in2 = new Intent(this, AlarmReceiverNotificationForTwoMonth.class);
in2.putExtra("MyMessage","Your 2 Monthly GST return is DUE on 19th August 2011.");
PI_2M_GST_2 = PendingIntent.getBroadcast(this, 1, in2, PendingIntent.FLAG_UPDATE_CURRENT);
Calendar calendar_GST_17_August_2011 = Calendar.getInstance();
calendar_GST_17_August_2011.setTimeInMillis(System.currentTimeMillis());
calendar_GST_17_August_2011.set(2011, 7, 17,mHour, mMinute, 0);
AM_2M_GST_2.set(AlarmManager.RTC_WAKEUP, calendar_GST_17_August_2011.getTimeInMillis(),PI_2M_GST_2);
AM_2M_GST_3 = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
Intent in3 = new Intent(this, AlarmReceiverNotificationForTwoMonth.class);
in3.putExtra("MyMessage","Your 2 Monthly GST return is DUE on 21st October 2011.");
PI_2M_GST_3 = PendingIntent.getBroadcast(this, 2, in3, PendingIntent.FLAG_UPDATE_CURRENT);
Calendar calendar_GST_19_October_2011 = Calendar.getInstance();
calendar_GST_19_October_2011.setTimeInMillis(System.currentTimeMillis());
calendar_GST_19_October_2011.set(2011, 9, 19,mHour, mMinute, 0);
AM_2M_GST_3.set(AlarmManager.RTC_WAKEUP, calendar_GST_19_October_2011.getTimeInMillis(),PI_2M_GST_3);
AM_2M_GST_4 = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
Intent in4 = new Intent(this, AlarmReceiverNotificationForTwoMonth.class);
in4.putExtra("MyMessage","Your 2 Monthly GST return is DUE on 19th December 2011.");
PI_2M_GST_4 = PendingIntent.getBroadcast(this, 3, in4, PendingIntent.FLAG_UPDATE_CURRENT);
Calendar calendar_GST_17_December_2011 = Calendar.getInstance();
calendar_GST_17_December_2011.setTimeInMillis(System.currentTimeMillis());
calendar_GST_17_December_2011.set(2011, 11, 17,mHour, mMinute, 0);
AM_2M_GST_4.set(AlarmManager.RTC_WAKEUP, calendar_GST_17_December_2011.getTimeInMillis(),PI_2M_GST_4);
AM_2M_GST_5 = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
Intent in5 = new Intent(this, AlarmReceiverNotificationForTwoMonth.class);
in5.putExtra("MyMessage","Your 2 Monthly GST return is DUE on 28th February 2012.");
PI_2M_GST_5 = PendingIntent.getBroadcast(this, 4, in5, PendingIntent.FLAG_UPDATE_CURRENT);
Calendar calendar_GST_26_February_2012 = Calendar.getInstance();
calendar_GST_26_February_2012.setTimeInMillis(System.currentTimeMillis());
calendar_GST_26_February_2012.set(2012, 1, 26,mHour, mMinute, 0);
AM_2M_GST_5.set(AlarmManager.RTC_WAKEUP, calendar_GST_26_February_2012.getTimeInMillis(),PI_2M_GST_5);
AM_2M_GST_6 = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
Intent in6 = new Intent(this, AlarmReceiverNotificationForTwoMonth.class);
in6.putExtra("MyMessage","Your 2 Monthly GST return is DUE on 29th April 2012.");
PI_2M_GST_6 = PendingIntent.getBroadcast(this, 5, in6, PendingIntent.FLAG_UPDATE_CURRENT);
Calendar calendar_GST_27_April_2012 = Calendar.getInstance();
calendar_GST_27_April_2012.setTimeInMillis(System.currentTimeMillis());
calendar_GST_27_April_2012.set(2012, 3, 27,mHour, mMinute, 0);
AM_2M_GST_6.set(AlarmManager.RTC_WAKEUP, calendar_GST_27_April_2012.getTimeInMillis(),PI_2M_GST_6);
AM_2M_GST_7 = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
Intent in7 = new Intent(this, AlarmReceiverNotificationForTwoMonth.class);
in7.putExtra("MyMessage","Your 2 Monthly GST return is DUE on 16th January 2012.");
PI_2M_GST_7 = PendingIntent.getBroadcast(this, 6, in7, PendingIntent.FLAG_UPDATE_CURRENT);
Calendar calendar_GST_16_January_2012 = Calendar.getInstance();
calendar_GST_16_January_2012.setTimeInMillis(System.currentTimeMillis());
calendar_GST_16_January_2012.set(2012, 0, 14,mHour, mMinute, 0);
AM_2M_GST_7.set(AlarmManager.RTC_WAKEUP, calendar_GST_16_January_2012.getTimeInMillis(),PI_2M_GST_7);
}
toogleButton:
AM_2M_GST_1.cancel(PI_2M_GST_1);
AM_2M_GST_2.cancel(PI_2M_GST_2);
AM_2M_GST_3.cancel(PI_2M_GST_3);
AM_2M_GST_4.cancel(PI_2M_GST_4);
AM_2M_GST_5.cancel(PI_2M_GST_5);
AM_2M_GST_6.cancel(PI_2M_GST_6);
AM_2M_PROVISIONAL_1.cancel(PI_2M_PROVISIONAL_1);
AM_2M_PROVISIONAL_2.cancel(PI_2M_PROVISIONAL_2);
AM_2M_PROVISIONAL_3.cancel(PI_2M_PROVISIONAL_3);
AM_2M_TERMINAL_1.cancel(PI_2M_TERMINAL_1);