当 Handler 的计数器不再计数时,如何停止它?也许你可以告诉我如何处理下面的代码。
public void handler() {
nHandler.postDelayed(new Runnable() {
@Override
public void run() {
viewFlipper.setDisplayedChild(8);
}
}, 20000);
}
利用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.