I have developed an android 2.1 application. In that I am using AsyncTask for doing background processing. It gets the data from the WebService.
The Problem is : When I leave the application, the background service remains active only. When I go to Settings->Applications->Running Applications it shows me that the application is running. I have to forcestop that application.
Is there any way to stop the background tasks automatically when user leaves the application ?
AsyncTask has a cancel method (http://developer.android.com/reference/android/os/AsyncTask.html#cancel(boolean) )
Invoke it when your Activity is going to stopped (onStop) state, or maybe paused - onPause depending on your needs, see Activity lifecycle for further explanation here: http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With