我尝试扩展ConuntDownTimer以这种方式添加方法暂停和恢复:
public class CountDown extends CountDownTimer {
private long resume;
private long millisInFuture;
private long countDownInterval;
public CountDown(long millisInFuture, long countDownInterval) {
super(millisInFuture,countDownInterval);
resume = millisInFuture;
this.millisInFuture = millisInFuture;
this.countDownInterval = countDownInterval;
}
public void play() {
// start
if( millisInFuture == resume ) {
super.start();
// restart
} else {
CountDown cd = new CountDown(resume, countDownInterval);
cd.play();
}
}
@Override
public void onTick(long millisUntilFinished) {
resume = millisUntilFinished;
// other code
}
}
问题是play方法中的“restart”,因为这样,我创建了另一个显示错误秒数的CountDown,因为几乎有两个事件“onTick”。我可以解决这个问题吗? (我希望我的英语可以理解)