Linking or casting?

I have a service that runs in the background. In my application, when X happens, I need to tell the service to do something. Is it better to contact this service or send a broadcast that the service will receive in order to force the service to perform the correct action?

thanks

+6
source share
1 answer

Binding is more efficient, I would recommend it.

The broadcast is more loosely coupled and therefore it may be easier to copy the code: you just transfer the intention to the Activity and no longer require more attention, and in the Service you do not need to do any work with connections, just register the receiver in onCreate() and unregister it onDestroy() . You actually do not need to track anything about the Service.

+4
source

Source: https://habr.com/ru/post/886979/


All Articles