Android - 任何允许使用暂停、恢复的计时器组件
Android - Any Timer component that allows to use pause,resume
我正在使用一个简单的 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();
我正在使用一个简单的 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();