CountDownTimer.cancel()
在以下代码中不起作用:
myTimer = new CountDownTimer(10000, 1000) {
public void onFinish() {
}
@Override
public void onTick(long millisUntilFinished) {
if(null != myObject){
myTimer.cancel();
}
}
}.start();
在上面的代码中,我启动了一个 CountDownTimer
,它检查对象是否不是 null
并相应地取消 Timer。该对象在任何时间点都由某个监听器设置。
请引用和建议。我在这里做的事情正确吗?
Solution By Gautier Hayoun :
Just made a drop-in replacement for CountDownTimer that you can cancel from within onTick : Github link– Gautier Hayoun Dec 12 '10 at 1:04
最佳答案
Gautier Hayoun 的解决方案:
刚刚替换了 CountDownTimer,您可以在 onTick 中取消它:Github link – Gautier Hayoun 2010 年 12 月 12 日 1:04
关于java - CountDownTimer.cancel() 在 Android 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6423848/