本文介绍了CountDownTimer.cancel()不工作在Android的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CountDownTimer.cancel()不工作在低于code:

  myTimer =新CountDownTimer(10000,1000){
    公共无效onFinish(){
    }
    @覆盖
    公共无效onTick(长millisUntilFinished){
        如果(NULL!= myObject的){
            myTimer.cancel();
        }
    }
}。开始();
 

在上面的code我已经开始了一个 CountDownTimer 其中检查对象不是和相应地取消计时器。该目的是通过一些听众在任何时间点设置的。请参考和建议。我做了正确的事吗?

解决方案

解决方案通过戈蒂埃Hayoun:

刚刚作出了一个简易替换为CountDownTimer,你可以从内部onTick取消: Github上的链接 - 戈蒂埃Hayoun 12月12日 10日1:04

CountDownTimer.cancel() is not working in the below code:

myTimer = new CountDownTimer(10000, 1000) {
    public void onFinish() {
    }
    @Override
    public void onTick(long millisUntilFinished) {
        if(null != myObject){
            myTimer.cancel();
        }
    }
}.start();

In the above code I have started a CountDownTimer which check if the object is not null and cancels the Timer accordingly. The object is set by some listener at any point of time.Please refer and suggest. Am I doing the right thing here?

解决方案

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

这篇关于CountDownTimer.cancel()不工作在Android的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 02:39