Hello, i have asked a question earlier which is similar to this and i got a solution which kind of works to an extent.but my problem is, the code in the else block never gets executes and that is where i want to cancel the alarm. cal.getTimeInMillis() is the set time for the an alarm to trigger an activity, while current.getTimeInMillis() is the current system time. Is this logic wrong? Please any suggestion will be greatly appreciated.
Calendar current = Calendar.getInstance();
if(current.getTimeInMillis() < cal.getTimeInMillis()){
current.add(Calendar.MINUTE, 15);
alarms.setRepeating(AlarmManager.RTC_WAKEUP, current.getTimeInMillis(), AlarmManager.INTERVAL_FIFTEEN_MINUTES, alarmIntent);
Toast.makeText(this, "Alarm will go of 15mins from now", Toast.LENGTH_SHORT).show();
}else {
alarms.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), alarmIntent);
Toast.makeText(this, "Alarm set in " + cal.getTimeInMillis() + " seconds",
Toast.LENGTH_LONG).show();
viewreminder.clearAlarm(); //alarm cancel method in an activity triggered from it.
}