Android问题集锦之二十 Activity has leaked window that was originall

               

今天调试程序时log中突然打印这样的错误,但是程序并没有crash,为了不放过一个错误,我决定调查一下。

当时是离开一个activity,然后提示是否退出此界面,接下来就打印此错误:

03-08 18:02:48.521: E/WindowManager(6340): Activity com.linc.megatron.activity.ExamActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40568ea8 that was originally added here03-08 18:02:48.521: E/WindowManager(6340): android.view.WindowLeaked: Activity com.linc.megatron.activity.ExamActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40568ea8 that was originally added here03-08 18:02:48.521: E/WindowManager(6340):  at android.view.ViewRoot.<init>(ViewRoot.java:264)03-08 18:02:48.521: E/WindowManager(6340):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)03-08 18:02:48.521: E/WindowManager(6340):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)03-08 18:02:48.521: E/WindowManager(6340):  at android.view.Window$LocalWindowManager.addView(Window.java:424)03-08 18:02:48.521: E/WindowManager(6340):  at android.app.Dialog.show(Dialog.java:241)03-08 18:02:48.521: E/WindowManager(6340):  at com.linc.megatron.base.BackKeyActivity.showDialog(BackKeyActivity.java:76)03-08 18:02:48.521: E/WindowManager(6340):  at com.linc.megatron.base.BackKeyActivity.onKeyDown(BackKeyActivity.java:62)03-08 18:02:48.521: E/WindowManager(6340):  at android.view.KeyEvent.dispatch(KeyEvent.java:1256)03-08 18:02:48.521: E/WindowManager(6340):  at android.app.Activity.dispatchKeyEvent(Activity.java:2078)03-08 18:02:48.521: E/WindowManager(6340):  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1709)03-08 18:02:48.521: E/WindowManager(6340):  at android.view.ViewRoot.deliverKeyEventToViewHierarchy(ViewRoot.java:2628)03-08 18:02:48.521: E/WindowManager(6340):  at android.view.ViewRoot.handleFinishedEvent(ViewRoot.java:2603)03-08 18:02:48.521: E/WindowManager(6340):  at android.view.ViewRoot.handleMessage(ViewRoot.java:1875)03-08 18:02:48.521: E/WindowManager(6340):  at android.os.Handler.dispatchMessage(Handler.java:99)03-08 18:02:48.521: E/WindowManager(6340):  at android.os.Looper.loop(Looper.java:123)03-08 18:02:48.521: E/WindowManager(6340):  at android.app.ActivityThread.main(ActivityThread.java:3687)03-08 18:02:48.521: E/WindowManager(6340):  at java.lang.reflect.Method.invokeNative(Native Method)03-08 18:02:48.521: E/WindowManager(6340):  at java.lang.reflect.Method.invoke(Method.java:507)03-08 18:02:48.521: E/WindowManager(6340):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)03-08 18:02:48.521: E/WindowManager(6340):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)03-08 18:02:48.521: E/WindowManager(6340):  at dalvik.system.NativeStart.main(Native Method)

显然,我用Dialog确认是否退出,但是activity销毁后并没有处理Dialog的退出。

解决办法:

知道了问题所在就容易解决问题了。只需要在activity销毁时关闭Dialog就好。

 @Override protected void onDestroy() {  if(mDialog != null) {   mDialog.dismiss();  }  super.onDestroy(); }



           

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值