0

我有一个代码

Handler handlerTimer2 = new Handler();
Runnable runnableTimer2 = new Runnable() {

    public void run() {
        try { afficherTimer2(); } catch (Exception e) {}
    }

};

public void afficherTimer2() {

    Log.d(MainActivity.APP, "ok afficher Timer 2");

    if (waitingBarTime < 15100) {
        waitingBar.setVisibility(ProgressBar.VISIBLE);
        waitingBar.setProgress((int)waitingBarTime);
        waitingBarTime = waitingBarTime + 1000;
        Log.d(MainActivity.APP, ""+waitingBarTime);
    }
    else
    {
        if (clientFound == true && waitingBarTime > 15000) {
            waitingBar.setVisibility(ProgressBar.INVISIBLE);
            clientFound = false;
            pointOfView.clear();
            parkDataBol = false;
            postForNewTaxi();
            waitingBarTime = 15200;
            runnable.run();
            handlerTimer2.removeCallbacks(runnableTimer2);
        }
        else
        {
            handlerTimer2.removeCallbacks(runnableTimer2);
            handlerTimer2.removeCallbacks(runnableTimer2, null);
            Log.d(MainActivity.APP, "ok afficher Timer 2 else 2");
        }

    }
    handlerTimer2.postDelayed(runnableTimer2, 1000);
}

但是当代码进入handlerTimer2.removeCallbacks(runnableTimer2); 它仍然运行处理程序:S 完成后如何停止此处理程序?

4

1 回答 1

1

有没有可能,这条线:

handlerTimer2.postDelayed(runnableTimer2, 1000);

导致定时器即使在它被删除后仍然运行?

于 2012-08-15T06:35:26.967 回答