Activity has leaked window that was originally added

后端 未结 30 3046
野趣味
野趣味 2020-11-21 05:48

What is this error, and why does it happen?

05-17 18:24:57.069: ERROR/WindowManager(18850): Activity com.mypkg.myP has leaked window com.android.internal.pol         


        
相关标签:
30条回答
  • 2020-11-21 06:07

    Dismiss the dialog when activity destroy

    @Override
    protected void onDestroy()
    {
        super.onDestroy();
        if (pDialog!=null && pDialog.isShowing()){
            pDialog.dismiss();
        }
    }
    
    0 讨论(0)
  • 2020-11-21 06:08

    This could help.

    if (! isFinishing()) {
    
        dialog.show();
    
        }
    
    0 讨论(0)
  • 2020-11-21 06:08

    Had the problem where I finished an Activity when a ProgressDialog was still shown.

    So first hide the Dialog and then finish the activity.

    0 讨论(0)
  • 2020-11-21 06:09

    Generally this issue occurs due to progress dialog : you can solve this by using any one of the following method in your activity:

     // 1):
              @Override
                    protected void onPause() {
                        super.onPause();
                        if ( yourProgressDialog!=null && yourProgressDialog.isShowing() )
                      {
                            yourProgressDialog.cancel();
                        }
                    }
    
           // 2) :
             @Override
                protected void onDestroy() {
                    super.onDestroy();
                    if ( yourProgressDialog!=null && yourProgressDialog.isShowing()
                   {
                        yourProgressDialog.cancel();
                    }
                }
    
    0 讨论(0)
  • 2020-11-21 06:10

    Best solution is just add dialog in try catch and dismiss dialog when exception occur

    Just use below code

     try {
            dialog.show();
        } catch (Exception e) {
            dialog.dismiss();
        }
    
    0 讨论(0)
  • 2020-11-21 06:10

    Best solution is put this before showing progressbar or progressDialog

    if (getApplicationContext().getWindow().getDecorView().isShown()) {
    
      //Show Your Progress Dialog
    
    }
    
    0 讨论(0)
提交回复
热议问题