java - Android pause/resume AsynTask -


i have ui thread(mainactivity) calling asyntask object(downloadmanager), which, in turn calls 3 threads (downloaderthread).

how pause/resume 3 downloaderthreads without pausing asyntask or ui thread?

following code have implemented pause functionality, when pause button clicked, app crashes dialog: "app has stopped". code:

downloadmanager (asyntask):

public void onpause() {     try{         t0.wait();         t1.wait();         t2.wait();         this.wait();     }catch (interruptedexception ex){      } } 

downloaderthread (implements runnable , passed thread instance in downloadmanager:

public class downloaderthread implements runnable {     private object mpauselock;     private boolean mpaused;     private boolean mfinished; public void run(){     android.os.process.setthreadpriority(android.os.process.thread_priority_background);     try{         while(!mfinished){             //do             synchronized (mpauselock){                 while (mpaused){                     try{                         mpauselock.wait();                     }catch (interruptedexception e){                      }                 }             }         }     } }  public void onpause(){     synchronized (mpauselock){         mpaused = true;     } } 

you can't pause asynctask once started. can, however, store progress when activity paused/destroyed , start progress once original activity. recommend best way complete task scenario use service.


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -