java - How can I specify publishProgress() to be called after x seconds inside a loop? -


I was looking for a path to call publication after x seconds in the Loop statement due to the Cross Generator Collector

It's what I have:

  protected voice downline background (zero ... parameters) {long size = source.length (); InputStream input = new FileInputStream (source); OutputStream Output = New FileOutputStream (Destination); // Byput transfer byte by input [] buf = new byte [1024]; Int len; Written long = 0; While ((len = input.read (buf)) gt; 0) {output.write (buf, 0, len); Written + = 1024; // It should be said after X second published progress (int) (written * 100 / size)); } Input.close (); Output.close (); }  

I have found scheduled exclorator service but I do not know how to implement it during the loop.

This solution will not block the UI thread because it uses AsyncTask

  long size = source.length (); InputStream input = new FileInputStream (source); OutputStream Output = New FileOutputStream (Destination); // Byput transfer byte by input [] buf = new byte [1024]; Int len; Written long = 0; While ((len = input.read (buf)) gt; 0) {output.write (buf, 0, len); Written + = 1024; Long size = source.length (); InputStream input = new FileInputStream (source); OutputStream Output = New FileOutputStream (Destination); // Byput transfer byte by input [] buf = new byte [1024]; Int len; Written long = 0; While ((len = input.read (buf)) gt; 0) {output.write (buf, 0, len); Written + = 1024; (New Assigna Tasks & lt; Zero, Zero, Zero & gt; () {@ Override Safe Volume Doignbackground (Zero ... Pars) {mEventDataSource.deleteAll ()} {Thread curentthread (.) Try (x * 1000) ;} Hold (Blocked exception E) {// TODO Auto-Generated Cache Block e.printStackTrace ();} Return Null;} @ Override Secure Zero at PostXextake (Zero Outcome) {// Progress after publishing it X Second (// (Int) (written * 100 / size));}}). carry about (); } Input.close (); Output.close ();  

Comments