When to bind a service and when not to bind a service

I am looking at the Android documentation and I was curious. When will you bind the service, not bind it? What benefits / limitations does it provide?

+3
source share
1 answer

When will you bind the service, not bind it?

The full answer to this requires several pages in (:: ahem: :) book. :-)

Service binding is a problem when it comes to configuration changes, such as screen shielding. Therefore, ceteris paribus, the use of the command template ( startService() ) is performed using the binding template ( bindService() ).

You need to use the command template if you want your service to start without any activity associated with it. Thus, a music player, bootloader with large files, or a cron job configured with AlarmManager will tend to use a command pattern.

Binding gives you access to a richer API, including support for data types that will not work with the command template (which is limited to what you can insert into the Bundle ).

+5
source

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


All Articles