Communication performance between Android services and activity

I can find some examples of creating a service, but it's hard for me to find a working example of how to send messages between Activity and a service. From what I can find, I think my options are to use Intents, AIDL, or use the service object itself for that matter .

In my case, my activity is the only action that will ever access the service, so a local service will be performed. When the activity is open, I want to see some status messages from the service that will arrive at a frequency of up to 20 Hz. Are there any restrictions on the number of messages per second that these communication methods will support? Basically, which method would be better for my situation?

Thanks.

+4
source share
2 answers

Since your Actvity and Service are part of the same application, then you do not need to use AIDL. You can just use your service as local .

+4
source

The limitation only affects the performance of your device. There are no limits on queries per second. A context switch is usually used, which uses quite a lot of CPU (compared to other parts of the transfer), but since you use a local service, you do not suffer from this. In any case, 20 Hz is not a problem. The best solution for you would be to use AIDL and set up a callback that the service can call to report its status.

There is a good example of how this is done in APIDemos.

+1
source

All Articles