How to flush pending messages and callbacks in a Handler
How to flush/dispatch all pending messages and callbacks which are waiting in a Handler?
I need this to deal with certain asynchronous events when my Service is being destroyed.
I want to dispatch all the messages/callbacks immedi开发者_开发知识库ately, not to remove them. I don't use any delayed messages.
Assuming you don't use any delayed messages, you have a queue of pending messages each of which must be processed in associated thread. This means that thread can not process next message unless current message processing is completed.
So, to summarize, if no delayed messages are used, you handler's message loop is already doing its best to flush the queue. The only thing that can make this flushing faster is better message processing. And this is not Handler's work.
精彩评论