2014-11-14 68 views
-1

我想在片段中創建progressdialog,但不斷顯示錯誤是泄露了最初在此處添加的窗口com.android.internal.policy.impl.phonewindow。請幫助這個我的代碼如何在內部類片段中添加進度對話框

private class ListDaftarHargaAsync extends AsyncTask<String, Void, String> { 

    @Override 
    protected void onPreExecute() { 
     progressDialog = new ProgressDialog(getActivity()); 
     progressDialog.setMessage("retrieving..."); 
     progressDialog.setIndeterminate(false); 
     progressDialog.setCancelable(false); 
    } 

    @Override 
    protected String doInBackground(String... params) { 
     try { 
      modelPost.setDataVouchers(); 
     } catch (JSONException e) { 
      e.printStackTrace(); 
     } 
     String result = modelPost.resultString; 
     if (result.length() != 0) { 
      progressDialog.dismiss(); 
     } 
     return null; 
    } 

    @Override 
    protected void onPostExecute(String result) { 
     progressDialog.dismiss(); 
     getActivity().runOnUiThread(new Runnable() { 
      @Override 
      public void run() { 
       fillDaftarHarga(); 
      } 
     }); 
    } 
} 
+2

哪裏progressDialog.show()?併發布完整的錯誤。並刪除progressDialog.dismiss();來自doInBackground。 '在那裏onPostExceute –

+0

刪除'progressDialog.dismiss();'在doInBackground – Yugesh

+0

我試過了,但仍然顯示相同的錯誤 – Ashadi

回答

0
leaked window com.android.internal.policy.impl.phonewindow that was originally added here. 

上述錯誤顯示,因爲你是在doInBackground調用progressDialog.dismiss();

+0

我試過了,但仍然顯示相同的錯誤 – Ashadi

+0

@Ashadi你試過了從doinbackgroud解僱) – duggu

1

檢查進度對話框顯示或不 ,你不能觸摸UI線程在doInBackground

@Override 
    protected void onPreExecute() { 
     progressDialog = new ProgressDialog(getActivity()); 
     progressDialog.setMessage("retrieving..."); 
     progressDialog.setIndeterminate(false); 
     progressDialog.setCancelable(false); 
     progressDialog.show(); 
    } 

    @Override 
    protected String doInBackground(String... params) { 
     try { 
      modelPost.setDataVouchers(); 
     } catch (JSONException e) { 
      e.printStackTrace(); 
     } 
     String result = modelPost.resultString; 
     return null; 
    } 

    @Override 
    protected void onPostExecute(String result) { 
     if (null != progressDialog && progressDialog.isShowing()) { 
      progressDialog.dismiss(); 
     } 
     getActivity().runOnUiThread(new Runnable() { 
      @Override 
      public void run() { 
       fillDaftarHarga(); 
      } 
     }); 
    } 
} 
+0

我試過了,但仍然顯示相同的錯誤 – Ashadi

+0

progressDialog = new ProgressDialog(CLASS_NAME.this); //嘗試這個 – inni

相關問題