2011-09-06 61 views
0

我是初學Android程序員。嘗試使用AsyncTask和ProgressDialog但遇到問題 - ProgressDialog無法解除。無法關閉Android應用程序中的ProgressDialog

下面的代碼是延伸活動的importExportActivity內 - 做了很多的谷歌搜索的

public class ProgressTask extends AsyncTask<Void, Void, Void> {  
    ProgressDialog dialog1 = new ProgressDialog(importExportActivity.this); 

    protected void onPreExecute() { 
      this.dialog1.show(importExportActivity.this, "", 
            "Please wait for few seconds...", true); 
    } 

    @Override 
    protected void onPostExecute(final Void success) { 
      dialog1.dismiss(); 
    } 

    protected Void doInBackground(final Void ... args) { 
       ...... did the main logic .... 
      return null; 
    } 
} 

,但似乎無法找到一個解決的辦法。

有人可以幫忙嗎?

+1

不'doInBackground(無效...)'爲止最完整?如果沒有,你的'ProgessDialog'不會解僱... –

+1

是的 - 請發佈「主要邏輯」代碼。 – SBerg413

+1

使最終的進度對話框 –

回答

0
protected void onPreExecute() { 
     this.dialog1.show(importExportActivity.this, "", 
           "Please wait for few seconds...", true); 
     super.onPreExecute(); 
} 

@Override 
protected void onPostExecute(final Void success) { 
     dialog1.dismiss(); 
     super.onPostExecute(RESULT); 
}  

礦以這種方式工作...

2

我覺得不必返回:

@Override 
protected void onPostExecute(final Void success) { 
     dialog1.dismiss(); 
    return; 

} 
1

回答我的問題。以下工作:

public class ProgressTask extends AsyncTask<Void, Void, Void> {  
ProgressDialog dialog1; 

protected void onPreExecute() { 
     dialog1 = ProgressDialog.show(importExportActivity.this, "", 
           "Please wait for few seconds...", true); 
} 

@Override 
protected void onPostExecute(final Void success) { 
     dialog1.dismiss(); 
} 

protected Void doInBackground(final Void ... args) { 
      ...... did the main logic .... 
     return null; 
} 

}

+0

您應該將自己的答案標記爲此問題的答案,這將有所幫助。 – Raffo