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.
精彩评论