首页 > 代码库 > android在学习——activity关闭和dialog.dismiss冲突的解决(Activity has leaked window com.android.internal.policy.impl.PhoneWindow)

android在学习——activity关闭和dialog.dismiss冲突的解决(Activity has leaked window com.android.internal.policy.impl.PhoneWindow)

当我们在退出整个程序的时候偶尔会出现这种报错:Activity has leaked window com.android.internal.policy.impl.PhoneWindow

其意思大概就是:窗体已经关闭了但是dialog仍然在显示,Activity has leaked window(activity渗透出窗体),大概就是这个意思。

那么就要在activity finish()之前将dialog dismiss()掉。

我的做法就是重写本activity的onDestroy()方法,在此方法中将dialog清除:

/**     * 此方法必须重写,以决绝退出activity时 dialog未dismiss而报错的bug     */    @Override    protected void onDestroy() {        // TODO Auto-generated method stub        try{            myDialog.dismiss();        }catch (Exception e) {            System.out.println("myDialog取消,失败!");            // TODO: handle exception        }        super.onDestroy();    }

 

android在学习——activity关闭和dialog.dismiss冲突的解决(Activity has leaked window com.android.internal.policy.impl.PhoneWindow)