Anroid 异常:Unable to add window 。。is not valid; is your activity running?
2014-08-18 20:44
781 查看
原因分析:
是由于有
activity时依附于另一个activity的,当被依附的activity产生错误的时候,该activity没有了靠山而产生错误(或者是调用了
一个已经被finish()的activity)。一般在创建alertdialog.builder是很容易见到。
对于这个错误还没有根本的解决办法,唯一的办法就是改变该activity依附于另一activity的事实,将其放入另一activity。
Android利用ActivityGroup加载子Activity,子Activity调用对话框,弹出:
ERROR/AndroidRuntime(10104): Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord@45a58ee0 is not valid; is your
activity running?
15:28:39.299: E/AndroidRuntime(1603): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
原因分析:
因为new对话框的时候,参数content 指定成了this,即指向当前子Activity的content。但子Activity是动态创建的,不能保证一直存在。其父Activity的content是稳定存在的,所以有下面的解决办法。
解决办法:
1.将content替换为getParent()即可。 注意:要创建dialog对象,上下文环境必须是activity。
2.看是不是每次都创建Dialog,有时候复用以前的Dialog,但以前的activity销毁了,会有这个问题的(我的就是这个问题)
是由于有
activity时依附于另一个activity的,当被依附的activity产生错误的时候,该activity没有了靠山而产生错误(或者是调用了
一个已经被finish()的activity)。一般在创建alertdialog.builder是很容易见到。
对于这个错误还没有根本的解决办法,唯一的办法就是改变该activity依附于另一activity的事实,将其放入另一activity。
Android利用ActivityGroup加载子Activity,子Activity调用对话框,弹出:
ERROR/AndroidRuntime(10104): Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord@45a58ee0 is not valid; is your
activity running?
15:28:39.299: E/AndroidRuntime(1603): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
原因分析:
因为new对话框的时候,参数content 指定成了this,即指向当前子Activity的content。但子Activity是动态创建的,不能保证一直存在。其父Activity的content是稳定存在的,所以有下面的解决办法。
解决办法:
1.将content替换为getParent()即可。 注意:要创建dialog对象,上下文环境必须是activity。
2.看是不是每次都创建Dialog,有时候复用以前的Dialog,但以前的activity销毁了,会有这个问题的(我的就是这个问题)
相关文章推荐
- Anroid 异常:Unable to add window …… is not valid; is your activity running?
- Anroid 异常:Unable to add window …… is not valid; is your activity running?
- Activity has leaked window that was originally added -界面退出时未关闭对话框异常 android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running? -
- popupwindow使用之异常-Unable to add window -- token null is not valid; is your activity running?
- Unable to add window is not valid; is your activity running?
- Unable to add window --token is not valid; is your activity running?
- - Unable to add window -- token null is not valid; is your activity running?
- view.WindowManager$BadTokenException: Unable to add window…is not valid; is your activity running?
- Unable to add window -- token android.os.BinderProxy@XXX is not valid; is your activity running?
- PopupWindow出现Unable to add window -- token null is not valid; is your activity running?
- Unable to add window -- token android.os.BinderProxy@xxx is not valid; is your activity running
- BadTokenException:Unable to add window …… is your activity running?is not valid; is your activity ru
- Unable to add window -- token null is not valid; is your activity running?
- unable to add window -- token null is not valid; is your activity running 错误解决办法
- Unable to add window -- token null is not valid; is your activity running?错误及其修改方法
- Unable to add window — token android.os.BinderProxy is not valid; is your activity running?
- Unable to add window -- token null is not valid; is your activity running?
- bug--Unable to add window –token is not valid; is your activity running?
- Unable to add window — token android.os.BinderProxy is not valid; is your activity running?
- PopupWindow出现Unable to add window -- token null is not valid; is your activity running?