我正在编写 Android 应用程序。有一个服务和scheduleTaskExecutor调用一种方法,每分钟减少小时和分钟。你知道为什么scheduleTaskExecutor每分钟执行两次吗?或者为什么if / else有时会被忽略?应该有一个开始延迟和延迟执行1分钟......谢谢!
/**
* Set reduce time thread
*/
public void setRunTime() {
// counting work
scheduleTaskExecutor.scheduleWithFixedDelay(new Runnable() {
public void run() {
reduceTime();
}
}, 1, 1, TimeUnit.MINUTES);
}
/**
* Reduce time
*
*/
public void reduceTime() {
if (this.getHour() != 0) {
if (this.getMinute() == 0) {
// set Minute
this.setMinute(60);
Log.i("test1", this.getHour() + " " + this.getMinute());
// reduce hour
this.setHour(getHour() - 1);
// Reduce time
this.setMinute(getMinute() - 1);
Log.i("test2", this.getHour() + " " + this.getMinute());
} else {
// Reduce time
this.setMinute(getMinute() - 1);
Log.i("test3", this.getHour() + " " + this.getMinute());
}
} else if (this.getHour() == 0 && this.getMinute() != 0) {
this.setMinute(getMinute() - 1);
} else {
this.scheduleTaskExecutor.shutdown();
this.stopSelf(getStartId());
}