Android Activity has leaked window that was originally added
今天调试程序时log中突然打印这样的错误,但是程序并没有crash,为了不放过一个错误,我决定调查一下。
当时是离开一个activity,然后提示是否退出此界面,接下来就打印此错误:
- ::48.521: E/WindowManager(): Activity com.linc.megatron.activity.ExamActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40568ea8 that was originally added here
- ::48.521: E/WindowManager(): android.view.WindowLeaked: Activity com.linc.megatron.activity.ExamActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40568ea8 that was originally added here
- ::48.521: E/WindowManager(): at android.view.ViewRoot.<init>(ViewRoot.java:)
- ::48.521: E/WindowManager(): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:)
- ::48.521: E/WindowManager(): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:)
- ::48.521: E/WindowManager(): at android.view.Window$LocalWindowManager.addView(Window.java:)
- ::48.521: E/WindowManager(): at android.app.Dialog.show(Dialog.java:)
- ::48.521: E/WindowManager(): at com.linc.megatron.base.BackKeyActivity.showDialog(BackKeyActivity.java:)
- ::48.521: E/WindowManager(): at com.linc.megatron.base.BackKeyActivity.onKeyDown(BackKeyActivity.java:)
- ::48.521: E/WindowManager(): at android.view.KeyEvent.dispatch(KeyEvent.java:)
- ::48.521: E/WindowManager(): at android.app.Activity.dispatchKeyEvent(Activity.java:)
- ::48.521: E/WindowManager(): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:)
- ::48.521: E/WindowManager(): at android.view.ViewRoot.deliverKeyEventToViewHierarchy(ViewRoot.java:)
- ::48.521: E/WindowManager(): at android.view.ViewRoot.handleFinishedEvent(ViewRoot.java:)
- ::48.521: E/WindowManager(): at android.view.ViewRoot.handleMessage(ViewRoot.java:)
- ::48.521: E/WindowManager(): at android.os.Handler.dispatchMessage(Handler.java:)
- ::48.521: E/WindowManager(): at android.os.Looper.loop(Looper.java:)
- ::48.521: E/WindowManager(): at android.app.ActivityThread.main(ActivityThread.java:)
- ::48.521: E/WindowManager(): at java.lang.reflect.Method.invokeNative(Native Method)
- ::48.521: E/WindowManager(): at java.lang.reflect.Method.invoke(Method.java:)
- ::48.521: E/WindowManager(): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:)
- ::48.521: E/WindowManager(): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:)
- ::48.521: E/WindowManager(): at dalvik.system.NativeStart.main(Native Method)
显然,我用Dialog确认是否退出,但是activity销毁后并没有处理Dialog的退出。
解决办法:
知道了问题所在就容易解决问题了。只需要在activity销毁时关闭Dialog就好。
@Override
protected void onDestroy() {
if(mDialog != null) {
mDialog.dismiss();
}
super.onDestroy();
}
Android Activity has leaked window that was originally added的更多相关文章
- Activity has leaked window that was originally added(以解决)
在编写Android程序的时候,遇到一个隐藏性问题.仔细查看LogCat,错误信息如下: 10-31 13:03:34.549: ERROR/WindowManager(444): Activi ...
- Activity has leaked window that was originally added
错误: E/WindowManager: android.view.WindowLeaked: Activity com.x.x.x has leaked window com.android.int ...
- Activity has leaked window that was originally added -界面退出时未关闭对话框异常 android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running? -
退出Activity时弹出登录框,点击确定finish当前Activity,结果报了这个错,随后查找资料知道 原因: 是因为退出Activity时没有关闭弹出框,出现了这个错误 解决方法: 只需要在a ...
- android在学习——activity关闭和dialog.dismiss冲突的解决(Activity has leaked window com.android.internal.policy.impl.PhoneWindow)
当我们在退出整个程序的时候偶尔会出现这种报错:Activity has leaked window com.android.internal.policy.impl.PhoneWindow 其意思大概 ...
- Android排错: has leaked window com.android.internal.policy.impl.PhoneWindow$ that was originally added here
异常场景: 经常在应用中需要处理一些耗时的工作,诸如读取大文件.访问网络资源等.为了避免因程序假死而带来的糟糕用户体验,通常我们可以通过线程+Handler或者Android提供的AsyncTask来 ...
- decorview that was originally added here or java.lang.IllegalArgumentException: View not attached to window manager
使用Dialog的时候,没少出现下面这两个报错 12-11 17:47:49.776: E/WindowManager(11461): android.view.WindowLeaked: Activ ...
- 【转】Android异常:that was originally added here
? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 02-19 15:08:02.228: E/WindowManager(22172): Activity ...
- Android Activity的加载模式和onActivityResult方法之间的冲突
前言 今天在调试程序时,发现在某一Activity上点击返回键会调用该Activity的onActivityResult()方法.我一开始用log,后来用断点跟踪调试半天,还是百思不得其解.因为之前其 ...
- Android failed creating starting window
/***************************************************************************** * Android failed crea ...
随机推荐
- 学习C语言偶遇【斐波那契数列】
1.今天学着学着就发现一个特别有趣的数列,斐波那契数列,感觉很好玩,翠花,上代码~~~~~~~ #include <stdio.h> int fibonaci(int i) { ) { ; ...
- python json结构
=====================================================json==============================import reques ...
- 洛谷 P1943 LocalMaxima_NOI导刊2009提高(1)
我们先考虑第i大数,比它大的数有(n-i)个,显然要使i是Local Maxima,比它大的数必须放在它后面,那么它是Local Maxima的期望是: 那么n个数中Local Maxima个数的期望 ...
- 7 numpy 傅里叶,提取图片轮廓
任务:提取照片中轮廓 本次处理图片:我的女神之一 江一燕 导入模块: #jyy.show() 会打开本地图片浏览器 使用傅里叶反转 获取实部,舍弃虚部 去除小数部分 将一维数 ...
- JPA学习(基于hibernate)
参考博客:https://blog.csdn.net/baidu_37107022/article/details/76572195 常用注解: https://blog.csdn.net/eastl ...
- ansible ad-hoc 参考
# 检查主机连接 # ansible test -m ping # 执行远程命令 # ansible test -m command -a 'uptime' # 执行主控端脚本 # ansible t ...
- 运维系列之一 Linux的文件与目录权限解析
在Linux中,万事万物皆文件,普通文件是文件,目录是文件,硬件设备也是文件,因此学习了解Linux中的文件非常重要. Linux中有三种文件类型: (1) 普通文件:又分为文本文件和二进制文件 (2 ...
- [转]十五天精通WCF——第九天 高级玩法之自定义Behavior
终于我又看完了二期爱情保卫战,太酸爽了,推荐链接:http://www.iqiyi.com/a_19rrgublqh.html?vfm=2008_aldbd,不多说,谁看谁入迷,下面言归正传, 看看这 ...
- 调用BPL包中的函数
BPL就是一种DLL,DLL的EXPORTS和GETPROCADDRESS()在BPL中一样好使. 要调用BPL中的方法也和调用DLL的一样.代码略.
- Spring学习笔记——Spring事务仅仅对执行时异常回滚
我们在使用Spring时候一般都知道事务在遇到异常的时候会回滚.岂不知Spring的事务默认仅仅有在发生执行时异常即:RunTimeException时才会发生事务,假设一个方法抛出Exception ...