0

Possible Duplicate:
how to stop ASyncTask thread in android

I have created an app which has an synch task doing something in the background. In my OnPostExecute function I created an intent to start an activity. The App is working perfectly fine till now. Now I wanted to stop that Asynch Task when the new actvity starts. How can I do that? Please help ......

Community
  • 1
  • 1
SACHIN DHIVARE
  • 115
  • 1
  • 1
  • 7

3 Answers3

1

Do this

MyAsyncTask task = new MyAsyncTask();
task.cancel(true); 

in your onStop();.

hardartcore
  • 16,886
  • 12
  • 75
  • 101
0

OnPostExecute() method will only be called after Completing DoInBackgroung() method. so you asynctask will finish while you are going to another Activity.

Bhavesh Patadiya
  • 25,740
  • 15
  • 81
  • 107
0

Your AsyncTask finishes after executing onPostExecute(), so you don't have to worry

Ralph
  • 21
  • 2