When To Bind A Service And When Not To Bind A Service
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"