Logic in mainMethod:
String todaydate=DateUtils.todayDateinToString();
if ( !todaydate.equals(localdate.get())) {
long currentMillis = System.currentTimeMillis();
if(currentMillis >= appProperties.nextCallMillis.get() ) {
localdate.set(currentMillis + 86400000);
callmethod();
}
appProperties.barCodeCallDate.set(DateUtils.todayDateinToString());
}
else{
appProperties.nextCallMillis.clear();
}
DateUtils.java
public static String todayDateinToString() {
String today = null;
try {
Date date = Calendar.getInstance().getTime();
// Display a date in day, month, year format
DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
today = formatter.format(date);
System.out.println("Today : " + today);
} catch (Exception e) {
e.printStackTrace();
}
return today;
}
i wrote this code to execute each day once after 24 hour interval.
Actual: its executing each day only once.
Expected: it should execute each day after 24 hour. For example i call method today at 11 am then it shouldn't call tomorrow before 11 am. It should call after 11 am. If I try to call day after tomorrow it should call before 11 am because that difference for next call is 24 hour.
please suggest me i am storing two date and nextCallMillis in locally .