android - AsyncTask Cannot execute task: the task has already been executed -


i know previous execution of asynctask running - question how finish , re-execute , because parameters 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 = 0; < count; i++){                     post post = params[0].getgetposts().getposts(i);                      if(!iscancelled()){                         try {  //some code 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 call task :

     log.d("mylog"," imagetask.getstatus()="+imagetask.getstatus());      if (imagetask.getstatus() == asynctask.status.running){          imagetask.cancel(true);      }      imagetask.execute(response); 

first, ths status, judging log finished. how running? , how restart asynctask properly?

from personal experience, asynctask instance 1 execution. isn't reusable. purpose, should re-initialize , execute.

hope help.

for reference, heading 'threading rules' here.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -