解决android中出现的“android.view.WindowLeaked: Activity com.tecsun.tsb.func.activity.GenericActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{2c4d2320 V.E..... R.....I. 0,0-6

解决android中出现的“android.view.WindowLeaked: Activity com.tecsun.tsb.func.activity.GenericActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{2c4d2320 V.E..... R.....I. 0,0-6_第1张图片
image.png

android.view.WindowLeaked: Activity com.tecsun.tsb.func.activity.GenericActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{2c4d2320 V.E..... R.....I. 0,0-650,400} that was originally added here

意思应该是window窗体溢出,就是activity活动销毁了,本次的dialog还没销毁,下一次进入activity活动的时候有重新创建了一个dialog,因此会造成窗体溢出

这个问题是接着上一章问题《解决android中出现的“android.view.WindowManager$BadTokenException: Unable to add window -- token”问题》发现的

看一下代码

public void showFinishActSingleBtnDialog(String content){
        if (singleBtnDialog != null && singleBtnDialog.isShowing()){
            singleBtnDialog.dismiss();
            singleBtnDialog = null;
        }
        if (!getActivity().isFinishing()){
            final SingleBtnDialog singleBtnDialog = new SingleBtnDialog(getActivity());
            singleBtnDialog.setDialogContent(content);
            singleBtnDialog.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    getActivity().finish();//这里可以看出activity销毁后没对dialog进行dismiss
                }
            });
            singleBtnDialog.show();
        }

//        if (singleBtnDialog == null){
//            singleBtnDialog = new SingleBtnDialog(getActivity());
//        }
//        singleBtnDialog.setDialogContent(content);
//        singleBtnDialog.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                getActivity().finish();
//            }
//        });
//        singleBtnDialog.show();
    }

在activity销毁后加上 singleBtnDialog.dismiss()就可以了

参考文章:http://www.cnblogs.com/awkflf11/p/5293267.html

你可能感兴趣的:(解决android中出现的“android.view.WindowLeaked: Activity com.tecsun.tsb.func.activity.GenericActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{2c4d2320 V.E..... R.....I. 0,0-6)