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.
Asked
Active
Viewed 73 times
-3
-
`internal threads are going on in the doInBackground` ?? internal threads in doInBackgroud? You should not use threads there. – greenapps Jul 21 '16 at 10:31
-
please add the code what you have tried. – Sai Jul 21 '16 at 10:32
-
`doInBackground is not getting called`. There is nothing in your post about this problem. – greenapps Jul 21 '16 at 10:34
-
show your code please – IntelliJ Amiya Jul 21 '16 at 10:56
-
visit http://stackoverflow.com/questions/6039158/android-cancel-async-task – Bharatesh Jul 21 '16 at 13:37
1 Answers
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