我有一个代码
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 完成后如何停止此处理程序?