-3

If any internal threads are going on in the doInBackground and it takes more time for the response to come back, and in the mean while if again I call the same async task, how to kill the previous threads in the doInBckground and run the new one?can anyone please help me?Thanks in advance.

Ragamai K
  • 3
  • 4

1 Answers1

1

According to Google you can't call the same asynctask object twice. If you do so it will throw an exception.

The task can be executed only once (an exception will be thrown if a second execution is attempted.)

For details see the documentation here. Read 'Threading rules' chapter.

As @greenapps said, don't use any thread inside doInBackground. doInBackground itself running under a thread.

If you want to cancel the previous asynctask that is currently running call cancel(true) method of asynctask object. If you rerun the task, then reinitialize that object and execute it again.

Md Sufi Khan
  • 1,751
  • 1
  • 14
  • 19