关于java.lang.IllegalArgumentException: View not attached to window manager 错误的分析
今天遇到一个很奇特的问题,当用户设置了PIN码,在锁屏界面正常解锁PIN码后,进入Launcher时显示com.android.phone 已停止运行。一开始猜想会不会是解锁PIN码的时候处理导致了Phone进程报错,通过log分析找到了问题的大概原因:
AndroidRuntime: FATAL EXCEPTION: main
AndroidRuntime: java.lang.IllegalArgumentException: View not attached to window manager
AndroidRuntime: at android.view.WindowManagerGlobal.findViewLocked(WindowManagerGlobal.java:385)
AndroidRuntime: at android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:287)
AndroidRuntime: at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:79)
AndroidRuntime: at android.app.Dialog.dismissDialog(Dialog.java:323)
AndroidRuntime: at android.app.Dialog.dismiss(Dialog.java:306)
AndroidRuntime: at com.android.stk.StkDialogActivity$4.onClick(StkDialogActivity.java:188)
AndroidRuntime: at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:169)
AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:99)
AndroidRuntime: at android.os.Looper.loop(Looper.java:153)
AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5299)
AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:511)
AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
AndroidRuntime: at com.android.stk.StkDialogActivity$4.onClick(StkDialogActivity.java:188)
这是开机识别到SIM卡之后弹出的STK对话框。那为什么会报com.android.phone已停止运行呢?
经过以上分析,我们可以大致猜测是因为STK引起的问题,既然是STK的问题那为什么会报phone的错误呢?如果是phone的错误那么从log中应该可以检索到phone相关的问题,为什么没有呢?那么我们接下来一一解答这些问题。
(1). 为什么报错com.android.phone已停止运行?
(2). 为什么会报View not attached to window manager错误?
(3). 为什么STKDialogActivity会被"杀掉"?
onCreate
onResume - mbSendResp[false], sim id: 0
... ...省略部分
onSaveInstanceState
onPause, sim id: 0
... ...省略部分
onDestroy-
onCreate
... ...省略部分
onRestoreInstanceState - [com.android.internal.telephony.cat.TextMessage@41fe7d80]
onResume - mbSendResp[false], sim id: 0
(4). 在STKDialogActivity被杀掉时,Dialog存在么?
WindowManager: Activity com.android.stk.StkDialogActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{41fea228 V.E..... R.....ID 0,0-1026,433} that was originally added here
WindowManager: android.view.WindowLeaked: Activity com.android.stk.StkDialogActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{41fea228 V.E..... R.....ID 0,0-1026,433} that was originally added here
WindowManager: at android.view.ViewRootImpl.<init>(ViewRootImpl.java:409)
WindowManager: at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:218)
WindowManager: at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
WindowManager: at android.app.Dialog.show(Dialog.java:281)
WindowManager: at android.app.AlertDialog$Builder.show(AlertDialog.java:951)
WindowManager: at com.android.stk.StkDialogActivity.onCreate(StkDialogActivity.java:192)
WindowManager: at android.app.Activity.performCreate(Activity.java:5122)
WindowManager: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
WindowManager: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
WindowManager: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)
WindowManager: at android.app.ActivityThread.access$600(ActivityThread.java:156)
WindowManager: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1340)
WindowManager: at android.os.Handler.dispatchMessage(Handler.java:99)
WindowManager: at android.os.Looper.loop(Looper.java:153)
WindowManager: at android.app.ActivityThread.main(ActivityThread.java:5299)
WindowManager: at java.lang.reflect.Method.invokeNative(Native Method)
WindowManager: at java.lang.reflect.Method.invoke(Method.java:511)
WindowManager: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
WindowManager: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
WindowManager: at dalvik.system.NativeStart.main(Native Method)
这里的WindowManager报错是什么意思呢? 这段log是WindowManager抛出的error错误,当我们的Dialog还没有dismiss时,如果此时该Activity被销毁了,那么就会出现以上错误,提示窗口泄漏(leaked window)。这里自己也做了一个实验,写一个demo,在Activity的onCreate方法中显示一个Dialog,然后直接调用finish方法。代码大致如下:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AlertDialog.Builder info = new Builder(this);
info.setTitle("Dialog").setPositiveButton("OK", null).setMessage("This is a Dialog");;
info.show();
finish();
}
直接将此程序run到模拟器或者真机上,查看log我们就能看到leaked window的报错信息。因此这也证明了前面我们的假设,即StkActivity在被销毁时,其所依附的 Dialog是存在的。
(5). 如何解决这个问题呢?
1. 使用Activity自带的Dialog控制方法
2. 限制Dialog的生命周期
关于java.lang.IllegalArgumentException: View not attached to window manager 错误的分析的更多相关文章
- java.lang.IllegalArgumentException: View not attached to window manager
公司项目线上bug: java.lang.IllegalArgumentException: View not attached to window manager at android.view.W ...
- 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 ...
- bug_ _java.lang.IllegalArgumentException: View not attached to window manager 2
今天遇到一个很奇特的问题,当用户设置了PIN码,在锁屏界面正常解锁PIN码后,进入Launcher时显示com.android.phone 已停止运行.一开始猜想会不会是解锁PIN码的时候处理导致了P ...
- bug_ _java.lang.IllegalArgumentException: View not attached to window manager
============= 1 view not attached to window manager 转自:http://hi.baidu.com/spare_h/blog/item/7fa3e ...
- Android中 View not attached to window manager错误的解决办法
前几日出现这样一个Bug是一个RuntimeException,详细信息是这样子的:java.lang.IllegalArgumentException: View not attached to w ...
- 关于dialog引起的 java.lang.IllegalArgumentException: View=com.android.internal.policy.impl.PhoneWindow$DecorView not attached to window manager 错误的分析
在跑Monkey测试的时候出现了一个比较特别的问题,先来看看Log: // CRASH: com.meizu.media.painter (pid 12491) // Short Msg: java. ...
- View not attached to window manager
java.lang.IllegalArgumentException: View not attached to window manager 在用ProgressDialog的时候,任务结束后Dis ...
- View not attached to window manager crash 的解决办法
View not attached to window manager crash 的解决办法 转自:http://stackoverflow.com/questions/22924825/view- ...
- spring报nested exception is java.lang.IllegalArgumentException: @EnableAsync annotation metadata was not injected错误
http://www.oschina.net/question/1539472_159699
随机推荐
- 初学JavaScript(入门一)
javaScript是世界上最流行的脚本语言 在我们的手机.电脑设备上所浏览的所有网页,以及基于HTML5手机App的交互都是通过javaScript驱动的,所以javascript是前端工作的一 ...
- 闲谈Future模式-订蛋糕
一. Future模式简介 Future有道翻译:n. 未来:前途:期货:将来时.我觉得用期货来解释比较合适.举个实际生活中例子来说吧,今天我女朋友过生日,我去蛋糕店准备给女朋友定个大蛋糕,超级大的那 ...
- 【加解密】关于DES加密算法的JAVA加密代码及C#解密代码
JAVA加密: package webdomain; import java.security.Key; import java.security.spec.AlgorithmParameterSpe ...
- Asp.net MVC Bundle 的使用与扩展
一.Asp.net 自带Bundle的使用: 1. 在Globale中注册与配置 BundleConfig.RegisterBundles(BundleTable.Bundles); public c ...
- 在mac上搭建python环境
原文出处:http://blog.justbilt.com/2014/07/02/setup_python_on_mac/ 这两天重新搞了下python的环境,发现好多地方还是容易忘记,因此有了这篇文 ...
- 阿里云存储OSS之九大使用技巧
http://www.biphp.com/cloud-computing/%E9%98%BF%E9%87%8C%E4%BA%91%E5%AD%98%E5%82%A8oss%E4%B9%8B%E4%B9 ...
- LINQ标准查询操作符(四) —AsEnumerable,Cast,OfType,ToArray,ToDictionary,ToList,ToLookup,First,Last,ElementAt
十.转换操作符 转换操作符是用来实现将输入对象的类型转变为序列的功能.名称以“As”开头的转换方法可更改源集合的静态类型但不枚举(延迟加载)此源集合.名称以“To”开头的方法可枚举(即时加载)源集合并 ...
- Mac下安装eclipse+python+pydev+numpy+matplotlib
*本人亲测是成功的安装过程 1.更新Mac系统默认低版本的python2.7.请参见这篇文章:http://jingyan.baidu.com/article/14bd256e39b63dbb6d26 ...
- AndroidStudio debug
1. view as text
- C# Common Keyword
[C# Common Keyword] 1.abstract Use the abstract modifier in a class declaration to indicate that a c ...