【问题描述】
如下报错
"Fatal Exception: java.lang.IllegalArgumentException: View=DecorView@66e8333[xxxActivity] not attached to window manager
at android.view.WindowManagerGlobal.findViewLocked(WindowManagerGlobal.java:511)
at android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:413)
at android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:168)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4439)
at android.app.ActivityThread.-wrap6(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1629)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:6524)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:941)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:831)"
【问题原因】
在移除view的时候,没有检查其activity的可用性,导致上述报错
【解决方案】
public static boolean isUseable(Activity mActivity) {
if ((null == mActivity) || mActivity.isFinishing() || mActivity.isRestricted()) {
return false;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
try {
if (mActivity.isDestroyed()) {
return false;
}
} catch (Exception e) {
e.printStackTrace();
} catch (Error e) {
e.printStackTrace();
}
}
return true;
}

博客主要描述了Android开发中出现的报错,即移除View时出现的IllegalArgumentException。原因是移除view时未检查其activity的可用性。虽未给出具体解决方案,但指出了问题关键所在,对解决此类报错有一定指导意义。

1203

被折叠的 条评论
为什么被折叠?



