我有一个Timer
它从00:00开始很好,但是当我想要停止它时我会调用cdTimer.cancel()
但是我无法重新启动Timer
旧的价值观又重新开始。我有这个方法:
private void StartTimer(){
final long EndTime = 3600;
cdtTimer = new CountDownTimer(EndTime*1000, 1000) {
public void onTick(long millisUntilFinished) {
long secondUntilFinished = (long) (millisUntilFinished/1000);
long secondsPassed = (EndTime - secondUntilFinished);
long minutesPassed = (long) (secondsPassed/60);
secondsPassed = secondsPassed%60;
tvCounterTimer.setText(String.format("%02d", minutesPassed) + ":" + String.format("%02d", secondsPassed));
}
public void onFinish() {
tvCounterTimer.setText("done!");
}
}.start();
}
我以为我可以保存值minutesPassed
和secondsPassed
,但我应该通过参数传递它们,对吗?
答案 0 :(得分:0)
要使计时器执行此操作
timer.cancel();
timer.purge();
要重新启动计时器,您必须重新实例化该对象,然后安排它。我会重新开始。