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: Activity TestActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{42204800 V.E..... R.....I. 0,0-640,164} that was originally added here

12-11 17:47:50.666: E/AndroidRuntime(11461): java.lang.IllegalArgumentException: View=com.android.internal.policy.impl.PhoneWindow$DecorView{42204800 V.E..... R.....I. 0,0-640,164} not attached to window manager

其原因就是:Dialog生命周期比Activity的生命周期长

所以,出现这个bug的时候,请检查创建这个Dialog的context所属的Activity是不是已经结束了,而dialog还在显示。

下面的测试代码可以复现上面提到的bug

public class TestActivity extends Activity{
    private Dialog mDialog;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);
        mDialog = new Dialog(this);
        mDialog.show();
        finish();//直接结束这个Activity,此时Dialog没有关闭,还在显示,生命周期比Activity长了,就会出现上面提到的Bug
}

解决方法:

1.请检查,是否还未等Dialog消失就提前结束Activity。如果是,肯定是你的逻辑出问题了,还没等Dialog结束就结束Activity。

2.不管什么情况,Activity一结束,确实要关闭Dialog。那么可在onStop或者onPause里面关闭dialog

@Override
protected void onStop() {
    super.onStop();
    if(mDialog.isShowing()){
        mDialog.dismiss();
    }
}
时间: 2024-10-29 19:11:37

decorview that was originally added here or 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.WindowManagerGlobal.findViewLocked(WindowManagerGlobal.java:406) at android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:308) at androi

关于dialog引起的 java.lang.IllegalArgumentException: View=com.android.internal.policy.impl.PhoneWindow$DecorView not attached to window manager 错误的分析

在跑Monkey测试的时候出现了一个比较特别的问题,先来看看Log: 1 // CRASH: com.meizu.media.painter (pid 12491) 2 3 // Short Msg: java.lang.IllegalArgumentException 4 5 // Long Msg: java.lang.IllegalArgumentException: View=com.android.internal.policy.impl.PhoneWindow$DecorView{2

java.lang.IllegalArgumentException: already added: Lorg/xmlpull/v1/XmlPullParser

在我的Eclipse Android app中出现了如下的错误 UNEXPECTED TOP-LEVEL EXCEPTION: java.lang.IllegalArgumentException: already added: Lorg/xmlpull/v1/XmlPullParser; .... Conversion to Dalvik format failed with error 1 此错误值出现在当我添加一个外部的jar文件到我的项目中时,我搜索了很多,没有找到一个有效的解决方法,我

图片缩放时java.lang.IllegalArgumentException: pointerIndex out of range解决方案

版权声明:本文为博主原创文章,未经博主允许不得转载. 06-03 20:45:24.143: E/AndroidRuntime(1230): FATAL EXCEPTION: main06-03 20:45:24.143: E/AndroidRuntime(1230): java.lang.IllegalArgumentException: pointerIndex out of range06-03 20:45:24.143: E/AndroidRuntime(1230): at androi

Android 多点触控错误处理(java.lang.IllegalArgumentException: pointerIndex out of range)

最近做View的多点触控时,每次第一次触控事件完美运行,第二次就直接崩了,错误信息如下: 01-03 00:05:44.220 4377-4410/system_process E/AndroidRuntime: *** FATAL EXCEPTION IN SYSTEM PROCESS: android.ui java.lang.IllegalArgumentException: pointerIndex out of range at android.view.MotionEvent.nat

图片缩放时java.lang.IllegalArgumentException: pointerIndex out of range

06-03 20:45:24.143: E/AndroidRuntime(1230): FATAL EXCEPTION: main 06-03 20:45:24.143: E/AndroidRuntime(1230): java.lang.IllegalArgumentException: pointerIndex out of range 06-03 20:45:24.143: E/AndroidRuntime(1230): at android.view.MotionEvent.native

Android广播接收器注册问题:Caused by: java.lang.IllegalArgumentException: Receiver not registered

1.程序中明明使用如下方法进行了广播的注册和解除注册: mContext.registerReceiver(downloadReceiver, filter); mContext.unregisterReceiver(downloadReceiver); 但程序运行过程中还是有一下问题: android.app.IntentReceiverLeaked: Activity *********** has leaked IntentReceiver *********** that was ori

启动hive错误:Exception in thread "main" java.lang.IllegalArgumentException

启动hive错误:Exception in thread "main" java.lang.IllegalArgumentException 2018-03-20 15:19:07 Gethin_H 阅读数 1357更多 分类专栏: Hive 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/Gethin_H/article/details/79626223 启动hive时报错了

Hive报错 Failed with exception java.io.IOException:java.lang.IllegalArgumentException: java.net.URISyntaxException: Relative path in absolute URI: ${system:user.name%7D

报错信息如下 Failed with exception java.io.IOException:java.lang.IllegalArgumentException: java.net.URISyntaxException: Relative path in absolute URI: ${system:user.name%7D 解决方法: 编辑 hive-site.xml 文件,添加下边的属性 <property> <name>system:java.io.tmpdir<