Activity has leaked window that was originally added

后端 未结 30 3787
野趣味
野趣味 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:18

    I have another solution for this, and would like to know if it seems valid to you: instead of dismissing in the onDestroy, which seems to be the leading solution, I'm extending ProgressDialog...

    public class MyProgressDialog extends ProgressDialog {
    
      private boolean isDismissed;
    
      public MyProgressDialog(Context context) {
        super(context);
      }
    
      @Override
      public void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        dismiss();
      }
    
      @Override
      public void dismiss() {
        if (isDismissed) {
          return;
        }
        try {
          super.dismiss();
        } catch (IllegalArgumentException e) {
          // ignore
        }
        isDismissed = true;
      }
    

    This is preferable, AFAIC, because you don't have to hold the progress dialog as a member, just fire(show) and forget

提交回复
热议问题