I have a search task which when the button is clicked a second time, it cancels the currently running task and recreates it.
if (_searchAsyncTask != null) {
// cancel if already running
_searchAsyncTask.cancel(true);
}
_searchAsyncTask = new SearchAsyncTask(this);
_searchAsyncTask.execute(data);
This is failing on the last line in the above code as if I had called the original async task again.
java.lang.IllegalStateException: Cannot execute task: the task has already been executed (a task can be executed only once)
Am I missing something? Do I need to wait until the original instance isCancelled()?