解决当activity销毁之后dismiss()或者show()方法报错

错误:java.lang.IllegalArgumentException: View=com.android.internal.policy.impl.PhoneWindow$DecorView{8668d93 V.E..... R.....I. 0,0-0,0} not attached to window manager
	at android.view.WindowManagerGlobal.findViewLocked(WindowManagerGlobal.java:417)
	at android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:343)
	at android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:121)
	at android.app.Dialog.dismissDialog(Dialog.java:355)
	at android.app.Dialog$1.run(Dialog.java:123)
	at android.os.Handler.handleCallback(Handler.java:815)
	at android.os.Handler.dispatchMessage(Handler.java:104)
	at android.os.Looper.loop(Looper.java:194)
	at android.app.ActivityThread.main(ActivityThread.java:5743)
	at java.lang.reflect.Method.invoke(Native Method)
	at java.lang.reflect.Method.invoke(Method.java:372)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1077)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:843)
public class BaseDialog extends Dialog {
	private Context mContext;
	WeakReference<Activity> weakReference = new WeakReference<Activity>(
			(Activity) mContext);

	protected BaseDialog(Context context) {
		super(context);
		this.mContext = context;
	}

	protected BaseDialog(Context context, int theme) {
		super(context, theme);
		this.mContext = context;
	}

	@Override
	public void show() {
		if (DialogUtil.isLiving((Activity) mContext)) {
			super.show();
		}
	}

	@Override
	public void dismiss() {
		if (DialogUtil.isShowing(this)
				&& DialogUtil.isExist_Living(weakReference)) {
			super.dismiss();
		}
	}

}


转自:http://blog.csdn.net/u013673799/article/details/72084846
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值