如果处理程序的计数器不再计数,我怎么能停止它? 也许你可以告诉我如何处理下面的代码。
public void handler() {
nHandler.postDelayed(new Runnable() {
@Override
public void run() {
viewFlipper.setDisplayedChild(8);
}
}, 20000);
}
答案 0 :(得分:8)
使用removeCallbacks
nHandler.removeCallbacks(nhandlerTask);
http://developer.android.com/reference/android/os/Handler.html#removeCallbacks(java.lang.Runnable)
public final void removeCallbacks (Runnable r)
Added in API level 1
Remove any pending posts of Runnable r that are in the message queue.