我正在使用一个简单的 countDownTimer
new CountDownTimer(30000, 1000) {
public void onTick(long millisUntilFinished) {
mTextField.setText("seconds remaining: " + millisUntilFinished / 1000);
}
public void onFinish() {
//do things
}
}.start();
但是现在,我想调用类似的东西
countDown.pause(); countDown.resume();
(这样存储剩余时间和进度):
我知道使用 CountDownTimer 是不可能的。
我如何使用计时器或处理程序来实现 与 CountDownTImer 中的 onFinish() 方法相同的行为?
最佳答案
这是一个非常好的库,可以做你想做的事:pause-resume-timer
它基本上是Timer
的子类。一个非常容易使用的库。您需要做的就是:
//This creates a timer which ticks every 2 seconds, and runs for 20 seconds.
Timer twoSecondTimer = new ExampleTimer(2000l, 20000l);
//Start the timer.
twoSecondTimer.start();
//Pause the timer.
twoSecondTimer.pause();
//Resume the timer
twoSecondTimer.resume();
关于Android - 任何允许使用暂停、恢复的计时器组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34011122/