【转】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 com.test.activity.TestActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@427bebc8 that was originally added here02-19 15:08:02.228: E/WindowManager(22172): android.view.WindowLeaked: Activity com.test.activity.TestActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@427bebc8 that was originally added here02-19 15:08:02.228: E/WindowManager(22172): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:438)02-19 15:08:02.228: E/WindowManager(22172): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:292)02-19 15:08:02.228: E/WindowManager(22172): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224)02-19 15:08:02.228: E/WindowManager(22172): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149)02-19 15:08:02.228: E/WindowManager(22172): at android.view.Window$LocalWindowManager.addView(Window.java:558)02-19 15:08:02.228: E/WindowManager(22172): at android.app.Dialog.show(Dialog.java:316)02-19 15:08:02.228: E/WindowManager(22172): at com.test.activity.TestActivity.onError(TestActivity.java:326)02-19 15:08:02.228: E/WindowManager(22172): at android.media.MediaPlayer$EventHandler.handleMessage(MediaPlayer.java:2113)02-19 15:08:02.228: E/WindowManager(22172): at android.os.Handler.dispatchMessage(Handler.java:99)02-19 15:08:02.228: E/WindowManager(22172): at android.os.Looper.loop(Looper.java:137)02-19 15:08:02.228: E/WindowManager(22172): at android.app.ActivityThread.main(ActivityThread.java:4881)02-19 15:08:02.228: E/WindowManager(22172): at java.lang.reflect.Method.invokeNative(Native Method)02-19 15:08:02.228: E/WindowManager(22172): at java.lang.reflect.Method.invoke(Method.java:511)02-19 15:08:02.228: E/WindowManager(22172): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:804)02-19 15:08:02.228: E/WindowManager(22172): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:571)02-19 15:08:02.228: E/WindowManager(22172): at dalvik.system.NativeStart.main(Native Method) |
这是我在播放视频弹出Dialog时,出现的异常。
分析:
经常在应用中需要处理一些耗时的工作,诸如读取大文件、访问网络资源等。为了避免因程序假死而带来的糟糕用户体验,通常我们可以通过线程+Handler或者Android提供的AsyncTask来解决该问题,并一般以ProgressDialog等提示性控件来告知用户当前的程序进度。而标题中描述的异常则会常常出现在这样的场景中,并且往往掩盖了导致异常的真正的罪魁祸首。
问题原因:
从 异常描述中,大致的意思是存在窗口句柄泄露,即未能及时销毁某个PhoneWindow。而这往往误导了我们,把过多的精力放在查找所谓的内存泄露上了。 其实存在这么一种情况,即因我们在非主线程中的某些操作不当而产生了一个严重的异常,从而强制当前Activity被关闭。而在关闭的同时,却没能及时的 调用dismiss来解除对ProgressDialog等的引用,从而系统抛出了标题中的错误,而掩盖了真正导致这个错误的异常信息。
解决方法之一:
本解决方法并不能真正的解决问题,但是在一定程度上可以将真正导致错误的异常信息显露出来。即重写Activity的onDestroy方法,在方法中调用dismiss来解除对ProgressDialog等的引用。
另外引出的一个异常
Unable to add window -- token android.os.BinderProxy@42f10c40 is not valid; is your activity running?
因为使用了线程,在线程完成以后弹出窗口。
这个时候如果用户在线程未执行完 按了返回按钮,activity已经onDestory了,
那么就会报出android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@4479b390 is not valid; is your activity running?
解决方法一在弹出窗口之前用Activity的isFinishing判断一下Activity是否还存在。
|
1
2
3
|
if (!Activity.isFinishing() && !dialog.isShowing()) { dialog.show();}
|
【转】Android异常:that was originally added here的更多相关文章
- Android Activity has leaked window that was originally added
今天调试程序时log中突然打印这样的错误,但是程序并没有crash,为了不放过一个错误,我决定调查一下. 当时是离开一个activity,然后提示是否退出此界面,接下来就打印此错误: - ::): A ...
- Android异常一、异步任务导致的窗口句柄泄漏问题(转)
05-05 10:36:41.009: E/WindowManager(4243): Activity com.tao.MyActivity has leaked window com.android ...
- Android异常:异步任务导致的窗口句柄泄漏问题
05-05 10:36:41.009: E/WindowManager(4243): Activity com.tao.MyActivity has leaked window com.android ...
- Activity has leaked window that was originally added
错误: E/WindowManager: android.view.WindowLeaked: Activity com.x.x.x has leaked window com.android.int ...
- 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 ...
- Activity has leaked window that was originally added(以解决)
在编写Android程序的时候,遇到一个隐藏性问题.仔细查看LogCat,错误信息如下: 10-31 13:03:34.549: ERROR/WindowManager(444): Activi ...
- Android异常:唤醒锁未授权。(Caused by: java.lang.SecurityException: Neither user 10044 nor current process has android.permission.WAKE_LOCK.)
Android异常:Caused by: java.lang.SecurityException: Neither user 10044 nor current process has android ...
- Android异常分析(转)
关于异常 异常? 异常就是一种程序中没有预料到的问题,既然是没有预料到的,就可能不在原有逻辑处理范围内,脱离了代码控制,软件可能会出现各种奇怪的现象.比如:android系统常见异常现象有应用无响应. ...
- Android异常:android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original
Android异常:android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that cr ...
随机推荐
- JS简单仿QQ聊天工具的制作
刚接触JS,对其充满了好奇,利用刚学到的一点知识,写了一个简单的仿QQ聊天的东西,其中还有很多的不足之处,有待慢慢提高. 功能:1.在输入框中输入内容,点击发送,即可在上方显示所输入内容. 2.点击‘ ...
- Sql server中DateDiff用法【转】
记录下来.每次使用都忘记.... DATEDIFF 函数 [日期和时间] 功能 返回两个日期之间的间隔. 语法 DATEDIFF ( date-part, date-expression-1, dat ...
- eclipse中配置c++开发环境 Eclipse + CDT + MinGW
转自eclipse中配置c++开发环境 Eclipse + CDT + MinGW 基本框架:Eclipse + CDT + MinGW 背景知识: CDT:CDT 是完全用 Java 实现的开放源码 ...
- VC下载文件 + 显示进度条
在codeproject里找了许久,发现这样一个VC下载文件并显示进度条的源码,于是添加了些中文注释: 1.下载线程函数: UINT DownloadFile(LPVOID pParam) { CWn ...
- 115太酷了,居然出了个TV版客户端
确实,智能电视代表了未来的方向,是智能家居的最重要客户端,TV也能做很多事情呢!!不要忘了这个市场,想想什么服务在TV上是最需要的? http://pc.115.com/tv.html
- 关于新版SDK报错You need to use a Theme.AppCompat theme的两种解决办法
android的一个小问题: Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme ( ...
- C语言实现定积分求解方法
求定积分的方法有很多种,下面是我总结的几种比较常用的方法. #include <stdio.h> #include <stdlib.h> #include <math.h ...
- Chapter 17 Replication
Chapter 17 Replication Table of Contents 17.1 Replication Configuration 17.2 Replication Implementat ...
- linux 复制文件时,报cp: omitting directory `XXX'
今天在用linux命令进行文件复制时omitting cp -i BBS /opt/workspace/apache-tomcat-6,参数用的是 -i),所以也不太熟悉,原来,还有子目录文件,而是必 ...
- bzoj1072
还是那句话s<=10 必然想到状压 题目唯一的难点在于怎么转移整除 整除即是mod d=0,我们用f[cur,j]表示选取状况为cur,余数为j的方案数 注意一个数a1a2a3…an (ai表示 ...