【转】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 here 02 - 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 here 02 - 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 ...
随机推荐
- C语言-07其它相关
预处理指令 /* 不带参数的宏定义 1.所有的预处理指令都是以#开头 2.预处理指令分3种 1> 宏定义 2> 条件编译 3> 文件包含 3.预处理指令在代码翻译成0和1之前执行 4 ...
- C# return dynamic/anonymous type value as function result
function: public static dynamic GetAppSecret() { //string[] result = new string[] { "", &q ...
- Solr4.8.0源码分析(27)之ImplicitDocRouter和CompositeIdRouter
同样在公司工作中发现了一个现象, 1.我用/solr/admin/collections?action=CREATE&name=collection&numShards=3&r ...
- 李洪强漫谈iOS开发[C语言-027]-自增与自减运算符
- SPRING IN ACTION 第4版笔记-第二章-001-用@Autowired\@ComponentScan、@Configuration、@Component实现自动装载bean
1. package soundsystem; import org.springframework.context.annotation.ComponentScan; import org.spri ...
- AlertDialog.Builder 样式设置
AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.AlertDia ...
- 在老项目中使用Gradle:更改默认目录结构
apply plugin: 'war' sourceCompatibility = 1.5 version = "1.0" //中央仓库 repositories { mavenC ...
- [OJ] Find Minimum in Rotated Sorted Array II
LintCode 160. Find Minimum in Rotated Sorted Array II (Medium) LeetCode 154. Find Minimum in Rotated ...
- mysqll 数据库相互堵塞问题
192.168.11.186 远程访问192.168.11.185 数据库 186上看到: centos6.5:/root#mysql -uroot -p'kjk123123' -h192.168.1 ...
- Trie 树(转)
看了很多 Trie 树的介绍, 这篇讲的最好,简单易懂(特别是代码部分),直接转载:http://www.cnblogs.com/dolphin0520/archive/2011/10/11/2207 ...