When I try to do a WindowManager.removeView(),
E/AndroidRuntime( 2445): java.lang.IllegalArgumentException: View=android.widget.LinearLayout{41a03700 V.E..... ......I. 0,0-0,0} not attached to window manager
E/AndroidRuntime( 2445): at android.view.WindowManagerGlobal.findViewLocked(WindowManagerGlobal.java:370)
E/AndroidRuntime( 2445): at android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:299)
E/AndroidRuntime( 2445): at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:79)
I get this fatal error because the view was not in the window manager. Is there no way to check if windowmanager had already added the view before? I do not see any such method in the source
You can check to see if the view's window token is null:
if(view.getWindowToken() != null){
WindowManager.removeView(view);
}
You could also just catch the exception:
try{
WindowManager.removeView(view);
}catch(IllegalArgumentException e){
Log.e(debug_tag, "view not found");
}
Its also a better way to check its already added on window or not.
if (view.getParent() != null)) {
windowsManager.removeView(view);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With