Question

If you have activities that communicate with a service, or another service communicating with a service, which "communication protocol" is faster to deliver it's message to the binding party?

Messages that are transmitted to/from the service are all strings or parcelable objects.

I am having difficulties deciding which method is faster if you want to send bulk data to another service or activity. I cannot find details about the processing speed of Intents or Messages sent by a Messenger.

Anybody experience with this?

Was it helpful?

Solution 2

You might want to consider LocalBroadcastManager.sendBroadcastSync() http://developer.android.com/reference/android/support/v4/content/LocalBroadcastManager.html#sendBroadcastSync(android.content.Intent)

If your activities and services are in the same process then it is is better to use LBM since it is faster and more secure. And it gives you the option of sending a broadcast 'sync' which means it is handled immediately, so it would probably qualify as 'fastest', even though messages/handler are otherwise faster then intents/receivers.

OTHER TIPS

For Intent, IntentResolver required time to find appropriate target as it will search through list of receivers. This case performence will depend on your system and number of receivers, IntentResolver required to search to find appropriate receiver.

On the other side if you send Message through Handler, it will use the Message Queue of the same thread and that case performance will depend on available message on that Queue.

So seems like message going to be faster then Intent or at least theoretically, but you can always write a short program to see the output.

But, if you have lots of data from to send from service to Activity you can think of another alternative solution where you write the data to a persistence store and after just notify your Activity that data is ready. upon receiving the notification Activity read the data from data source. In this way, if user receive a phone call or get disrupted in between you data is safe.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top