I don't see the point of using a local 开发者_JS百科service in Android. If I want to do backgound stuff, I can create a thread and use Handlers.
Creating a local service is a big headache, you have to mess with Binders, worry about the start/stop/bind/unbind lifecycle, etc.
What does a local service get me that a thread doesn't ?
With a Service
you can respond to system broadcasts and carry out some action in the background without the user having to start your app. For example, Listen will periodically download podcasts in the background without having to manually start the app.
If you want to run things in background without the onpause effect you do it by a service. For example if you want to play music, if you do that on the activity level once the user leaves the activity it will stop as the activity goes to pause, and eventually the system will kill it later. Services too can be killed.
Another example is if you want to retrieve for example the weather info, you would not start an activity for such thing as the user doesn't need to see an UI for a scheduled weather update progress.
For now just loose the bind stuff behind Services, they work without those too very well.
精彩评论