2
진행 상황이 진행 중일 때 사용자가 뒤로 버튼을 클릭하면 어떻게 될지 궁금합니다. 현재 진행 상황 은 사용자가 현재 활동을 종료하고 이전 활동 또는 다른 응용 프로그램으로 돌아갈 때에 저장해야한다는 것이 나에게 들었습니다. 나는 파일을 다운로드하고 사용자가 sync 버튼을 누를 때 진행 막대를 보여주는 코드를 작성했다. 그것은 다음과 같다 :사용자가 android에서 뒤로 버튼을 클릭 할 때 진행률 막대의 진행 상태를 저장하는 방법
활동이 얻을 때 활동 종료 사용자가 다시 버튼을 누르면하고있는 동안 때public class DownloadVideoTask extends AsyncTask<String, String, String>{
@Override
protected String doInBackground(String... downloadurl) {
int count;
try{
URL url = new URL(downloadurl[0]);
URLConnection connection = url.openConnection();
connection.connect();
int lengthOfFile = connection.getContentLength();
Log.d(TAG, "Length of file: " + lengthOfFile);
InputStream inputStream = new BufferedInputStream(url.openStream());
OutputStream outputStream = new FileOutputStream("/sdcard/drona_video.mp4");
byte data[] = new byte[1024];
long total = 0;
while((count = inputStream.read(data))!= -1){
total += count;
publishProgress("" + (int)((total*100)/lengthOfFile));
outputStream.write(data, 0, count);
}
dbAdapter.insertVideoBytesInVideoDownloadsTable(id, data);
//bundle.putByteArray("videoBytesArray", data);
outputStream.flush();
outputStream.close();
inputStream.close();
}catch(Exception e){
return null;
}
return null;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
//showDialog(DIALOG_DOWNLOAD_PROGRESS);
syncBtn.setEnabled(false);
progressBar.setMax(100);
progressBar.setVisibility(View.VISIBLE);
txtProgressPercentage.setVisibility(View.VISIBLE);
}
@Override
protected void onPostExecute(String result) {
//dismissDialog(DIALOG_DOWNLOAD_PROGRESS);
//mProgressDialog.dismiss();
progressBar.setVisibility(View.INVISIBLE);
progressBar.setSaveEnabled(true);
txtProgressPercentage.setVisibility(View.INVISIBLE);
syncBtn.setVisibility(View.INVISIBLE);
playBtn.setVisibility(View.VISIBLE);
}
@Override
protected void onProgressUpdate(String... progress) {
Log.d(TAG, progress[0]);
//mProgressDialog.setProgress(Integer.parseInt(progress[0]));
progressBar.setProgress(Integer.parseInt(progress[0]));
txtProgressPercentage.setText(progress[0] + "%");
}
}
나는 그것이 진행률 표시 줄의 상태를 저장하도록 위에서 언급 한 코드 사이에 넣어 몇 가지 코드가 필요 열어 놓은 곳에서 다시 시작합니다. 도와주세요. 당신은 당신이 종료 정적 매개 변수에 ProgressBar의 상태를 저장할 수 있습니다