我已经创建了一个服务,它将使用循环每小时调用Method,但不能完全是小时O'Clock(N:00), 我的代码
try {
do {
Thread.sleep(Integer.parseInt(UtilitiesGlobals.ONE_HOUR));
publishProgress();
} while (RUNNING);
} catch (Exception e) {
e.printStackTrace();
}
那么,我怎样才能打电话给每一小时O'Clock(1:00,2:00,3:00,4:00 ......)
答案 0 :(得分:0)
Timer timer = new Timer ();
TimerTask hourlyTask = new TimerTask () {
@Override
public void run () {
// your code here.
}
};
// schedule the task to run starting now and then every hour.
timer.schedule (hourlyTask, 0l, 1000*60*60);
答案 1 :(得分:0)
final Handler handler = new Handler();
handler.postDelayed( new Runnable() {
@Override
public void run() {
todoItems.clear();
publishProgress();
handler.postDelayed( this, 60 * 60 );
}
}, 60 * 60 );*