【转】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 ...
随机推荐
- CentOS下Redis 2.2.14安装配置详解(转载)
一. 下载redis最新版本2.2.14 cd /usr/local/src wget –c http://redis.googlecode.com/files/redis-2.2.14.tar.gz ...
- Effective Java之并发
并发本身有两个概念:1.互斥性:2.可见性: 先来说一下可见性,就是让共享的变量在进程间可以及时获得最新版本的数据:这里比较简单的方式是为可能被并发修改的全局变量添加上volatile关键字:vola ...
- nutch 索引
nutch开发环境搭建 nutch-1.3导入eclipse nutch-1.7导入eclipse nutch部署 nutch-1.3linux下部署 nutch-1. ...
- Waterfall———瀑布流布局插件, 类似于 Pinterest、花瓣、发现啦。
瀑布流布局插件, 类似于 Pinterest.花瓣.发现啦. En 中文 文档 下载 下载waterfall插件最新版本. 使用 html: <div id="container&qu ...
- bzoj 3851: 2048 dp优化
3851: 2048 Time Limit: 2 Sec Memory Limit: 64 MBSubmit: 22 Solved: 9[Submit][Status] Description T ...
- javascript mvc
http://www.webjx.com/javascript/jsajax-15996.html http://blog.csdn.net/jjfat/article/details/7963608 ...
- Android 模拟登陆 保存密码(信息)到手机中 文件信息读取
package com.wuyou.login; import java.io.IOException; import java.util.Map; import android.app.Activi ...
- 【BZOJ1901】 Zju2112 Dynamic Rankings(树套树)
[题意] 给定一个含有n个数的序列a[1],a[2],a[3]--a[n], 程序必须回答这样的询问:对于给定的i,j,k,在a[i],a[i+1],a[i+2]--a[j]中第k小的数是多少(1≤k ...
- git stash的使用
https://git-scm.com/docs/git-stash 在git svn的时候使用,提交记录的时候,有部分文件的修改不需要commit. 在向svn进行git svn dcommit的时 ...
- Uncompressing Linux___ done, booting the kernel_tekkamanninja-ChinaUnix博客
今天用主线Linux内核移植到MINI6410,主线内核2.6.37.1基本已经支持了MINI6410的板子,所以移植到能够启动起来的阶段很简单,但是在移植的时候还是出现了一个比较常见的问题: MIN ...