I know that previous execution of AsyncTask is running - my question is how do I finish it and re-execute , because my parameters for it has been changed.
protected class ImageDownloadTask extends AsyncTask<Response, Void, Void>{
@Override
protected void onPreExecute() {
super.onPreExecute();
poolTasks.add(this);
}
@Override
protected Void doInBackground(Response... params) {
int count=params[0].getGetPosts().getPostsCount();
for(int i = 0; i < count; i++){
Post post = params[0].getGetPosts().getPosts(i);
if(!isCancelled()){
try {
//some code to download images
} catch (Exception e) {
}
publishProgress();
} else poolTasks.remove(this);
}
return null;
}
@Override
protected void onProgressUpdate(Void... values) {
super.onProgressUpdate(values);
adapter.notifyDataSetChanged();
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
poolTasks.remove(this);
adapter.notifyDataSetChanged();
}
@Override
protected void onCancelled() {
super.onCancelled();
poolTasks.remove(this);
}
}
now on parameters update that's how I call this task :
Log.d("MyLog"," imageTask.getStatus()="+imageTask.getStatus());
if (imageTask.getStatus() == AsyncTask.Status.RUNNING){
imageTask.cancel(true);
}
imageTask.execute(response);
first, ths status, judging by the Log is FINISHED. so how could it be running? and how do I restart this AsyncTask properly?
0 comments:
Post a Comment