2

私のアプリケーションでは、ユーザーが3Gをオンにしたときにタイムアウトを設定したい...一定の時間が経過した後、3Gをオフにします..私の問題は、スケジュールされたタイマーをキャンセルすることです.. timer.cancel( ) .. プログラムがエラーをスローする

clearTimeout() メソッドを呼び出すときの問題の原因..

Timer timer;

class RemindTask extends TimerTask {
           public void run() {
               //do something when time's up 
                log("timer","running the timertask..");//my custom log method
                timer.cancel(); //Terminate the timer thread
            }

}

public void setTimeout(int seconds) {
    timer = new Timer();
    timer.schedule(new RemindTask(), seconds*1000);

}

public void clearTimeout(){
    log("timer", "cancelling the timer task");//my custom log method
    timer.cancel();
    timer.purge();
}

私を助けてください..私はアンドロイドの初心者です..

4

1 に答える 1

5

Android には、 と を持つクラスCountdownTimerstart()ありcancel()ます。

于 2013-09-01T04:59:43.160 に答える