In my Activity I use a class which extends from AsyncTask and a parameter which is an instance of that AsyncTask. When I call mInstanceOfAT.execute("")
everything is fine.
But the app crash when I press an update button which calls again the AsyncTask(In case the network job didnt work). Cause then appears an Exception which says
Cannot execute task: the task has
already been executed (a task can be
executed only once)
I have tried calling cancel(true) for the instance of the Asyctask, but it doesnt work either. The only solution so far it's to create new instances of the Asyntask. Is that the correct way?
Thanks.
Best Answer
AsyncTask
instances can only be used one time.Instead, just call your task like
new MyAsyncTask().execute("");
From the AsyncTask API docs:
Threading rules
There are a few threading rules that must be followed for this class to work properly: