开发者

How to flush pending messages and callbacks in a Handler

开发者 https://www.devze.com 2023-03-12 23:24 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号