For any specific instance, call . Note that it uses the instance itself to determine which callbacks to unregister, so if you are creating a new instance each time a post is made, you need to make sure you have references to the exact to cancel. Example:Runnable
Handler.removeCallbacks()
Runnable
Runnable
Handler myHandler = new Handler();
Runnable myRunnable = new Runnable() {
public void run() {
//Some interesting task
}
};
You can call to post another callback to the message queue at other places in your code, and remove all pending callbacks with myHandler.postDelayed(myRunnable, x)
myHandler.removeCallbacks(myRunnable)
Unfortunately, you cannot simply "clear" the entire for a , even if you make a request for the object associated with it because the methods for adding and removing items are package protected (only classes within the android.os package can call them). You may have to create a thin subclass to manage a list of s as they are posted/executed...or look at another paradigm for passing your messages between each MessageQueue
Handler
MessageQueue
Handler
Runnable
Activity
Hope that Helps!