/**
* 计时操作 改变界面的倒计时信息
*/
private void timerOperation() {
recLen = RECENT_SECOND;
mTimer = new Timer();
timerTask = new TimerTask() {
@Override
public void run() {
// TODO Auto-generated method stub
recLen--;
if (recLen >= 0) {
Message msg = new Message();
msg.what = SECOND_UPDATE;
msg.arg1 = recLen;
handler.sendMessage(msg);
}
}
};
mTimer.schedule(timerTask, PROGRESS_DELAY, PROGRESS_PERIOD);
}在关闭时使用: private void closeTimer() {
if (timerTask != null) {
timerTask.cancel();
timerTask = null;
}
if (mTimer != null) {
mTimer.cancel();
mTimer = null;
}
}不然,会出现计时过快的现象
另外值得一提的是:
如果Timer 或者 timerTask调用了cancel方法,那么不能直接才启用Timer 或者 timerTask了。所以重复使用时,重新new是必要的。
1991

被折叠的 条评论
为什么被折叠?



