今天调试程序时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的更多相关文章

  1. Activity has leaked window that was originally added(以解决)

     在编写Android程序的时候,遇到一个隐藏性问题.仔细查看LogCat,错误信息如下: 10-31 13:03:34.549: ERROR/WindowManager(444): Activi ...

  2. Activity has leaked window that was originally added

    错误: E/WindowManager: android.view.WindowLeaked: Activity com.x.x.x has leaked window com.android.int ...

  3. 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 ...

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

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

  5. Android排错: has leaked window com.android.internal.policy.impl.PhoneWindow$ that was originally added here

    异常场景: 经常在应用中需要处理一些耗时的工作,诸如读取大文件.访问网络资源等.为了避免因程序假死而带来的糟糕用户体验,通常我们可以通过线程+Handler或者Android提供的AsyncTask来 ...

  6. 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 ...

  7. 【转】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  ...

  8. Android Activity的加载模式和onActivityResult方法之间的冲突

    前言 今天在调试程序时,发现在某一Activity上点击返回键会调用该Activity的onActivityResult()方法.我一开始用log,后来用断点跟踪调试半天,还是百思不得其解.因为之前其 ...

  9. Android failed creating starting window

    /***************************************************************************** * Android failed crea ...

随机推荐

  1. Python学习【第7篇】:Python之常用模块2

    hashlib,configparser,logging模块 一.常用模块二 hashlib模块 hashlib提供了常见的摘要算法,如md5和sha1等等. 那么什么是摘要算法呢?摘要算法又称为哈希 ...

  2. ES6学习历程(字符串的扩展)

    字符串的扩展 在看这一节的时候前半部分写的都是关于unicode的内容,我个人感觉这部分在实际的开发中用的很少,所以不打算在做记录,等届时用到再有针对性的看,所以就将在ES6里面关于字符串操作的一些新 ...

  3. mysql中文乱码归纳总结

    今天使用sqlalchemy往mysql数据库里插入数据的时候,发生了错误,因为字段包含中文,所以报错.在问题解决之后做一个总结.   mysql中文乱码包括几个方面.mysql服务器层面.mysql ...

  4. 取代PHP原生函数的一些扩展包

    前言 虽然程序员无时无刻都在造轮子,但造轮子也有效率之分,用好轮子才能造出好"

  5. Python爬虫基础--分布式爬取贝壳网房屋信息(Server)

    1. server_code01 2. server_code02 3. server_code03

  6. (ccf)201709-4 通信网络

    #include<iostream> #include<memory.h> #include<stack> #include<string> #incl ...

  7. Flask-SQLAlchemy中解决1366报错

    会报下面这个1366的错 安装MySQL驱动(我升级过Python,所以要再装一遍) 本想安装MySQL官方驱动mysql-connector-python的,然而官方目前只支持到3.4 我又懒,所以 ...

  8. vue 使用echarts

    import echarts from 'echarts'   <div id="kocGrow" style="width: 600px;height: 300p ...

  9. 【codeforces 801B】Valued Keys

    [题目链接]:http://codeforces.com/contest/801/problem/B [题意] 定义一个对两个字符串x,y的f(x,y)函数; 返回的是一个字符串; 这个返回的字符串的 ...

  10. hdu 4171 最短路

    #include<stdio.h> #include<string.h> #include<queue> #include<iostream> usin ...