2016-07-04 35 views
0

我打電話解僱,但我仍然得到錯誤:由於我的自定義對話框而導致泄漏窗口錯誤?

activity has leaked window com.android.internal.policy.PhoneWindow$DecorView that was originally added here 

跟此錯誤:

Ĵava.lang.IllegalArgumentException: View=com.android.internal.policy.PhoneWindow$DecorView{a49b58 V.E...... R....... 0,0-1368,224} not attached to window manager

這是我的自定義進度對話框:

public class CustomProgressDialog extends ProgressDialog { 

    private AnimationDrawable animation; 

    public CustomProgressDialog(Context context) { 
     super(context); 
    } 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.custom_progress_dialog); 


     ImageView la = (ImageView) findViewById(R.id.animation); 
     if (la != null) { 

      la.setBackgroundResource(R.drawable.custom_progress_dialog_animation); 
      animation = (AnimationDrawable) la.getBackground(); 
     } 

    } 

    @Override 
    public void show() { 
     super.show(); 
     animation.start(); 
    } 

    @Override 
    public void dismiss() { 
     super.dismiss(); 
     animation.stop(); 
    } 


    @Override 
    public void setOnCancelListener(OnCancelListener listener) { 
     super.setOnCancelListener(listener); 
     dismiss(); 
    } 
} 

這是我如何在活動中實施它:

private void showProgressDialog() { 

     customProgressDialog = new CustomProgressDialog(this); 
     customProgressDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); 
     customProgressDialog.show(); 
     //so it cannot be closed by user first one lets back button cancel it 
     //customProgressDialog.setCanceledOnTouchOutside(false); 
     customProgressDialog.setCancelable(false); 
     autoProgressShutdown(); 

    } 

    private void hideProgressDialog() { 
     pdCanceller.removeCallbacksAndMessages(null); 
     if (customProgressDialog != null) { 

      customProgressDialog.dismiss(); 
     } 
    } 

並會在登錄我有這樣的方法叫殺任何對話框打開:

private void takeToHome() { 

     hideProgressDialog(); 

     Intent homeIntent = new Intent(this, MainHome.class); 
     homeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
     homeIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); 
     homeIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
     homeIntent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); 
     startActivity(homeIntent); 

     customProgressDialog.dismiss(); 
     finish(); 
    } 

一對夫婦的變化我想已經失敗過,在hideProgress對話框中我改變了它從.hide()來。解僱()然後我有目的地稱呼它。在再次完成之前關閉()以確保沒有錯過任何東西,但錯誤仍然存​​在於切換到主頁並且有時會崩潰,它會隨之消失。

我有一個異步任務發生時顯示的對話框,如登錄,以確保用戶知道它正在加載,一旦完成動畫停止,它似乎被隱藏,但完成它崩潰---現在我在整個應用程序中使用異步調用,並在整個應用程序中崩潰時,貫穿整個應用程序。任何關於我在做什麼的錯誤或者我如何在切換到其他活動之前銷燬對話框

回答

0

請嘗試此customProgressDialog爲null,然後只應創建一個對象,根據我第一次創建的思想對象,然後再嘗試創建object.Then僅此泄漏的Windows錯誤來,並檢查 時,對話框將被解僱

if (dialog != null && dialog.isShowing()) { 
        dialog.dismiss(); 
       } 

如果你想顯示在該TIEM一個對話框,以應用此codition。

if (dialog != null && !dialog.isShowing()) { 
     dialog.show(); 
    } 
+0

沒有工作,在Destroy工作 – Lion789