今天在写程序中遇到如下问题,如此怪异,在网上找了很多,终于解决了问题:
java.lang.IllegalArgumentException: View not attached to window manager
解决方法:
在调用系统相机拍照相片后返回protected void onActivityResult(int requestCode, int resultCode, Intent data)方法,那么可能会抛出这个异常,原因就是返回activity后,重新运行onCreate方法,那些view重新画出来,某些需要初始化的变量没有设置好。处理这个问题,只要有两种方法:(关键第二点)
1. 限制屏幕翻转
可在AndroidManifest.xml中设定android:screenOrientation=”portrait”
2. 如果是需要翻转的,那么限制那些view做重画动作。
可在AndroidManifest.xml中设定android:configChanges=”orientation|keyboardHidden|navigation”
分享到:
相关推荐
在这种情况下,需要确保在Activity的生命周期方法中妥善处理Dialog的关闭,防止出现“IllegalArgumentException: View not attached to window manager”的错误。 以上是关于Android Dialog使用的一些关键点和最佳...
然而,不恰当的使用方式可能会导致各种问题,其中`IllegalArgumentException: View not attached to window manager`就是一个典型错误。这篇文章将深入探讨如何正确地在Android中使用Dialog,以及如何避免遇到上述...
Usually, you'll need to call the following class methods to create your backstage view: AddCommand: add a single command button such as "Save", "Save As" or "Exit". AddView: add a button with ...
extended scan code E0 0004h = extended scan code E1 6 2 Not used 8 4 Device specific information <br> <br>The Save Window <br>The Save button saves all captured data to the ...
layoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; layoutParams.flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_LAYOUT_NO_...