이것을 실행하면 프로그레스바가 52%에서 다시 초기화되어버립니다;

다운로드는  백그라운드에서 멈추질않고 sdcard로 계속 다운받아지구용ㅋ

무한루프에 빠져버립니다 한마디로 다운이 완료돼면 다시 처음부터 데이타가 초기화되고 다시 받아집니다 ㅋㅋ

문제점이 어떤건지 지적좀해주시면 감사하겠습니당.


import java.io.*;
import java.net.*;

import android.app.*;
import android.content.*;
import android.os.*;
import android.view.*;
import android.widget.*;

public class Web extends Activity {
 int mValue;
 ProgressDialog mProgress;

 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.network_downhtml);
  Button btn = (Button)findViewById(R.id.down);
  btn.setOnClickListener(new Button.OnClickListener() {

   public void onClick(View v) {
    new AccumulateTask().execute(100);
   }
  });
 }
 class AccumulateTask extends AsyncTask<Integer, Integer, Integer> {
  protected void onPreExecute() {
   mValue=0;
   mProgress = new ProgressDialog(Web.this);
   mProgress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
   mProgress.setTitle("DownLoading");
   mProgress.setMessage("Wait...");
   mProgress.setCancelable(false);
   mProgress.setProgress(0);
   mProgress.setButton("Cancel", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int whichButton) {
     cancel(true);
    }
   });
   mProgress.show();
  }
  protected Integer doInBackground(Integer... arg0) {
   while (isCancelled() == false) {
    mValue++;
    if (mValue <= 100) {
     
    try {
     URL url = new URL("url 극비 ㅈㅅ");  
        HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();  
        urlConnection.setRequestMethod("GET");  
        urlConnection.setDoOutput(true);  
        
        urlConnection.connect();  
        File SDCardRoot = Environment.getExternalStorageDirectory();  
        File file = new File(SDCardRoot, "compass123.zip");  
        FileOutputStream fileOutput = new FileOutputStream(file);  
        InputStream inputStream = urlConnection.getInputStream();  
       
        int totalSize = urlConnection.getContentLength();  
        int downloadedSize = 0;  
        
        
        byte[] buffer = new byte[1024];  
        int bufferLength = 0;
         while ((bufferLength = inputStream.read(buffer))>0 ) {  
         fileOutput.write(buffer, 0, bufferLength);  
         downloadedSize += bufferLength;  
             updateProgress(downloadedSize, totalSize);
        }  
     fileOutput.close(); 
//     } catch (MalformedURLException e) {  
//      e.printStackTrace();  
//     } catch (IOException e) {  
//      e.printStackTrace();  
//     } 
     Thread.sleep(1000);
     } catch (InterruptedException e) {   
      e.printStackTrace();
     }catch (MalformedURLException e) {  
      e.printStackTrace();  
     } catch (IOException e) {  
      e.printStackTrace();  
     } 
     } else {
     break;
    }
    publishProgress(mValue);
   }
   return mValue;
  }
  protected void onProgressUpdate(Integer... progress) {        
      mProgress.setProgress(progress[0]);    
     }
     protected void onPostExecute(Integer result) {
      removeDialog(0);
     }
     protected void onCancelled() {
      super.onCancelled();
     }
 }
 public void updateProgress(int downloadedSize, int totalSize) {
  mProgress.setProgress(100 * downloadedSize/totalSize);
 }
}