편집 : 대화 상자를 표시하면 아무런 문제없이 모든 작업이 진행됩니다. 하지만 진행률을 추가하면 대화 상자가 닫히지 않습니다 (메서드 onPostExecute()가 실행되지 않음).Android AsyncTask onPostExecute 메서드
onPostExecute 메서드가 실행되지 않습니다. 나는 어디에서 실수를합니까? (에뮬레이터와 장치에서 같은 결과가 나타납니다.) 이 메서드에 대한 재정의 표기법을 사용해야하는지 잘 모르겠습니다.
이것은 현재로서는 대략적인 해결책입니다. 그것은 매번 작동하지만, 적절하지 않고 좋은 것이 아닙니다. 내가하고있는 일 : * tabgroupactivity를 사용하여 하위 활동을 시작합니다. * 그런 다음 하위 활동의 다른 활동으로 이동하므로 부모의 현재 하위입니다. * 웹보기가 있는데 여기에 대한 정보가 표시됩니다. 덧글 .. 뭐든간에 * webView *에 표시된 콘텐츠에 링크가 있습니다.이 링크를 클릭하면 PDF 파일을 다운로드하기 시작합니다.
파일이 다운로드되는 경우 : 내가 while 루프 후 대화 상자를 호출하려고하면, 난 그냥 그것을 얻을하지 않도록
while ((current = bis.read()) != -1) {
read = read + current;
baf.append((byte) current);
Dialog.setProgress(read);
if(Dialog.isShowing() && read+2*current>file_size){
Dialog.dismiss();
Dialog.cancel();
}
}
내 대화 오브젝트는, disapeared된다. 그래서 내가 한 것은 웹 사이트에서 새로운 버퍼를 얻을 때마다 대화 상자가 여전히 보이는지 확인하고 현재 바이트와 함께 읽은 바이트의 양이 파일의 전체 크기보다 큰지를 확인합니다. while 루프에서 대화 상자를 닫으십시오. 나는 이는 파일 크기가 == (바이트의 양)를 읽을 사용하여 시도하지만 파일이
private class DownloadPDFFile extends AsyncTask<String, Integer, Void> {
private ProgressDialog Dialog = new ProgressDialog(getParent());
protected void onPreExecute() {
Dialog.setMessage("Downloading PDF file..");
Dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
Dialog.setCancelable(false);
// Dialog.setMax(1000);
Dialog.setProgress(0);
Dialog.show();
}
protected Void doInBackground(String... urls) {
File file=null;
int file_size = 0;
try {
URL url = new URL(urls[0]);
URLConnection urlConnection = url.openConnection();
urlConnection.connect();
file_size = urlConnection.getContentLength();
Dialog.setMax(file_size);
} catch (IOException e) {
}
try {
URL url1 = new URL(urls[0]); // you can // link
file = new File("skm_intern_pdf.pdf");
URLConnection ucon = url1.openConnection();
InputStream is = ucon.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayBuffer baf = new ByteArrayBuffer(5000);
int read = 0;
int current = 0;
while ((current = bis.read()) != -1) {
read = read + current;
baf.append((byte) current);
Dialog.setProgress(read);
if(Dialog.isShowing() && read+2*current>file_size){
Dialog.dismiss();
Dialog.cancel();
}
}
FileOutputStream fos = openFileOutput("skm_pdf.pdf",
Context.MODE_WORLD_WRITEABLE);
fos.write(baf.toByteArray());
fos.flush();
fos.close();
} catch (IOException e) {
}
return null;
}
onPostExecute는 절대로 호출되지 않는다고 결론을 내린 이유는 무엇입니까? 일부 logcat을 게시하십시오. – kaspermoerch
sys.out +는 Dialog.dismiss()를하고 있습니다. Logcat을 게시하면 임의의 메시지가 수천 개가됩니다. –
정말 logcat을 게시하십시오. Log.i (디버그 태그, 메시지)를 사용하여 앱을 추적 할 수 있습니다. Eclipse에서는 디버그 태그를 사용하여 필터를 만들 수 있으므로 로그 만 인쇄됩니다. – Huang