How to cancel a service when the Android application ends

How can I stop the service from starting in the background when my application is finished? I want the service to be active when the application is in the background, but when the application is closed, I need the service to stop.

I am calling to start a service in the onStop () method that belongs to myActivity and I stopped it in the onStart () method.

But the big problem is that I kill the application process, which I see in the Logcat that the service is still running.

Can anyone tell me how do I start the service only when my application is in the background?

+3


source to share


1 answer


You don't need to handle it manually if you start the service with the .bind () method in your Application class. As in the documentation: "A bound service only works as long as another application component is bound to it."



You can find this information in the first 5 sentences in the official guide http://developer.android.com/guide/components/services.html . Please consider reading the guide for posting questions on SO.

0


source







All Articles