用法一
Runnable mRunnable = new Runnable() {
@Override
public void run() {
// TODO
}
};
mHandler.removeCallbacks(mRunnable);//取消待执行的消息
mHandler.postDelayed(mRunnable, 500/* delayMillis */);
用法二
通过匿名类
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
// TODO
}
}, 500 /* delayMillis */);
大多情况需要采用用法一
Handler类
android.os.Handler
android.os.Handler.Callback
android.os.Handler.handleMessage(Message)
android.os.Handler.dispatchMessage(Message)
android.os.Handler.Handler()
android.os.Handler.Handler(Callback)
android.os.Handler.Handler(Looper)
android.os.Handler.Handler(Looper, Callback)
android.os.Handler.getMessageName(Message)
android.os.Handler.obtainMessage()
android.os.Handler.obtainMessage(int)
android.os.Handler.obtainMessage(int, Object)
android.os.Handler.obtainMessage(int, int, int)
android.os.Handler.obtainMessage(int, int, int, Object)
android.os.Handler.post(Runnable)
android.os.Handler.postAtTime(Runnable, long)
android.os.Handler.postAtTime(Runnable, Object, long)
android.os.Handler.postDelayed(Runnable, long)
android.os.Handler.postAtFrontOfQueue(Runnable)
android.os.Handler.removeCallbacks(Runnable)
android.os.Handler.removeCallbacks(Runnable, Object)
android.os.Handler.sendMessage(Message)
android.os.Handler.sendEmptyMessage(int)
android.os.Handler.sendEmptyMessageDelayed(int, long)
android.os.Handler.sendEmptyMessageAtTime(int, long)
android.os.Handler.sendMessageDelayed(Message, long)
android.os.Handler.sendMessageAtTime(Message, long)
android.os.Handler.sendMessageAtFrontOfQueue(Message)
android.os.Handler.removeMessages(int)
android.os.Handler.removeMessages(int, Object)
android.os.Handler.removeCallbacksAndMessages(Object)
android.os.Handler.hasMessages(int)
android.os.Handler.hasMessages(int, Object)
android.os.Handler.getLooper()
android.os.Handler.dump(Printer, String)
android.os.Handler.toString()