Android - Avoiding a service to stop when pressing back button
I created and binded a service in an activity and I would like to know how I can avoiding the android application to stop when I press the back button.
When the back button is pressed the onDestroy method is called and I unbinded the service in this method. I try to prevent it开发者_运维技巧 by taking care of the back button event and manually call for onStop() method but it always called onDestroy after, why?
There are two ways of starting a Service. The first is using Context.startService
- this will run the Service until it is explicitly stopped using Context.stopService
or Service.stopSelf
. The second method is to call Context.bindService
. If the Service has not already been started then this will start it. However it will only run as long as at least one binding to it exists- once the last binding has been released the Service will be stopped. It sounds as if you might be using the second method to start the Service. See http://developer.android.com/intl/de/reference/android/app/Service.html#ServiceLifecycle for more info
精彩评论