Handler mHandler = new Handler(); //post a delayed message to the message queue mHandler.sendMessageDelayed(msg, delayTime); //remove the message from the queue before it is processed mHandler.removeMessages(messageType, messageObject);
Handler mHandler = new Handler(); //post a message to the message queue mHandler.sendMessage(msg); //remove any pending messages with the same message type mHandler.removeMessages(messageType);In this example, we create a new Handler object and post a message to the message queue. We then use the removeMessages method to remove any pending messages with the same message type from the queue. The android.os package library provides the Handler class.