Skip to content Skip to sidebar Skip to footer

When To Bind A Service And When Not To Bind A Service

I have been paging through the Android documentation and I was curious. When would you bind a service as opposed to not binding the service? What advantages/limitations does it pro

Solution 1:

When would you bind a service as opposed to not binding the service?

A full answer to that requires a few pages in (::ahem::) a book. :-)

Binding to a service presents challenges when it comes to deal with configuration changes, such as screen rotations. Hence, all else being equal, using the command pattern (startService()) beats using the binding pattern (bindService()).

You have to use the command pattern if you want your service to run without any activity around to be bound to it. So, a music player, a large-file downloader, or a cron job set up with AlarmManager would all tend to use the command pattern.

Binding gives you access to a richer API, including support for data types that will not work with the command pattern (which is limited to things you can stick in a Bundle).

Post a Comment for "When To Bind A Service And When Not To Bind A Service"