开发者

Broadcast delivery and performance

开发者 https://www.devze.com 2023-03-24 03:02 出处:网络
I am guessing that the broadcast messages are posted to the message queue of the receiving thread and delivered through the looper. Are the broadcasts delivered before other messages in the message q

I am guessing that the broadcast messages are posted to the message queue of the receiving thread and delivered through the looper. Are the broadcasts delivered before other messages in the message queue or just appended to the end of the queue? I have no specific need or anything like that, just wanted to know out of curiosity.

What is the performance overhead (CPU and memory) for using broadcasts for IPC between a service开发者_开发问答 and an Activity?

GL


Are the broadcasts delivered before other messages in the message queue or just appended to the end of the queue?

I think they just go on the end of the queue. The easy way to test this is to post() a couple of Runnables to the queue that each sleep for a bit, then send yourself a broadcast. If the Runnables are all processed before the broadcast, it went to the end. If the broadcast is processed before later Runnables, then it got injected at the front.

What is the performance overhead (CPU and memory) for using broadcasts for IPC between a service and an Activity?

Modest, as @jlindenbaum suggests. I wouldn't suggest trying to fire off thousands of the things, and there are lighter-weight solutions for in-process work (e.g., Messenger).


I've never noticed a considerable strain on devices using this.

It's the only "sane" way, that I've found, to communicate between a Service and an Activity without causing issues on UI threads.

0

精彩评论

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