【发布时间】:2012-03-15 01:12:42
【问题描述】:
我正在为 android 开发自动配置文件更改应用程序...这是我在 android 上开发的第二个应用程序,所以不知道 android 开发的所有花里胡哨...
无论如何...我在计算下一次计时器代码应该执行的时间时遇到了一些问题...主要问题是从午夜到第二天的时间...
例如,假设用户创建了一个睡眠配置文件,该配置文件从晚上 10:30 开始,一直持续到第二天早上 8 点……以此为例,执行处于我放置在代码,但是 nextUpdateInterval 设置不正确......我仍在试图弄清楚如何计算/计算跨越到第二天的时间,此时我开始认为我可能会让这个任务过于复杂?有什么建议吗?
这里是sn-p的代码:
timer.scheduleAtFixedRate( new TimerTask() {
public void run() {
//..... some code to convert user stored times into proper time formats
//PM to PM
if(isFromTimePM == true && isToTimePM == true){
}//PM to AM
else if(isFromTimePM == true && isToTimePM == false){
if(rightNowDate.getTime() >= fromDate.getTime() && rightNowDate.getTime() >= toDate.getTime()){
foundProfileIndex = i;
i = profileArrayListSize;
nextUpdateInterval = rightNowDate.getTime() - toDate.getTime();
}
}//AM to AM
else if(isFromTimePM == false && isToTimePM == false){
}//AM to PM
else if(isFromTimePM == false && isToTimePM == true){
}}, 0, nextUpdateInterval);
谢谢, P
【问题讨论】: