java.lang.IllegalArgumentException - not attached to window manager
来源:互联网 发布:手机瓷砖软件效果图 编辑:程序博客网 时间:2024/06/05 06:54
前言:
做安卓的苦逼就是,公司的测试机测试完了都没问题,用户的奇葩机器出现 各种问题!
最近新版本更新的头一天,就在友盟上发现出现的如题的错误信息,而且是一片。但是看机型好像大部分都是比较老的手机。
为什么会报View not attached to window manager错误?
这个错误的意思是说我们所操作的View没有被纳入window manager的管理。
我们知道所有的窗口创建和管理都是依附于window manager的,因此Dialog的创建也不例外。Dialog的创建流程通过查看源码可以知道,在Dialog的构造函数中,创建了一个Window对象,但我们知道Window对象并不是用于显示的,真正用于显示的是View对象。因此通过Dialog的show方法构造了一个mDecor的View对象,并最终通过WindowManager的addView()方法显示Dialog。
在网络上搜索后发现,多数情况下出现这种错误,都是在dismiss Dialog时,发现创建该Dialog的Activity存在而导致的。
比如在界面上显示一个Dialog,当任务处理结束后再Dismiss Dialog。如果在Dialog显示期间,该Activity因为某种原因被杀掉且又重新启动了,那么当任务结束时,Dismiss Dialog的时候WindowManager检查,就会发现该Dialog所属的Activity已经不存在了(重新启动了一次,是一个新的Activity),所以会报IllegalArgumentException: View not attached to window manager.
通过以上分析我们可以知道在STK Dialog在执行dismiss方法时,发现启动它的Activity已经不见了,被杀掉了(现在这个是重新启动的),所以才报错出现异常。
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(); }<strong> </strong>这个例子:我们在onCreate中让dialog.show();并且接着finish()这个Activity,再次启动时就会出现not attached to window manager。
我的处理方法是:
@Overrideprotected void onDestroy() {dismissDialog();super.onDestroy();}在onDestroy()中dismiss掉dialog,当然可以添加判断:
if(dialog.isShowing()){ dialog.dismiss();}
1 0
- java.lang.illegalargumentexception view not attached to window manager 解决
- java.lang.IllegalArgumentException: View not attached to window manager
- java.lang.IllegalArgumentException: View not attached to window manager
- java.lang.IllegalArgumentException: View not attached to window manager
- java.lang.IllegalArgumentException - not attached to window manager
- java.lang.IllegalArgumentException: View not attached to window manager
- java.lang.IllegalArgumentException: View not attached to window manager when dismissing dialog
- 关于java.lang.IllegalArgumentException: View not attached to window manager 错误的分析
- 关于java.lang.IllegalArgumentException: View not attached to window manager 错误的分析
- 关于java.lang.IllegalArgumentException: View not attached to window manager 错误的分析
- 关于java.lang.IllegalArgumentException: View not attached to window manager 错误的分析
- java.lang.IllegalArgumentException: View not attached to window manager when dismissing dialog
- 关于java.lang.IllegalArgumentException: View not attached to window manager 错误的分析
- 关于java.lang.IllegalArgumentException: View not attached to window manager 错误的分析
- 关于java.lang.IllegalArgumentException: View not attached to window manager 错误的分析
- android笔记之关于java.lang.IllegalArgumentException: View not attached to window manager 错误的分析
- 使用Activity.isfinishing()解决java.lang.IllegalArgumentException: View not attached to window manager
- 关于java.lang.IllegalArgumentException: View not attached to window manager 错误的分析
- MiniGUI.cfg 文件详解
- leetCode_Word Ladder【BFS】
- 关于系统(ios7+)自带的向右滑动手势返回上一个界面的一个问题
- linux查找命令、find、grep找到需要的文件
- IOS获取设备的IP
- java.lang.IllegalArgumentException - not attached to window manager
- 树莓派3 串口使用 raspberry pi 3B+ uart boot overlay(最全树莓派串口使用)
- Cardboard中取消周边黑框方法
- HDU 5755 (高斯消元)
- AndroidStudio CalendarView的属性介绍
- Maven远程存储库
- Java学习笔记(一):CMD使用
- 网络流 (基础学习)
- java实时推送消息goeasy实现