Skip to content Skip to sidebar Skip to footer

Is There A Way To Check If Android Windowmanager Already Contains A View?

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

Solution 1:

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");
}

Solution 2:

Its also a better way to check its already added on window or not.

if(view.getParent()!=null)) {
    windowsManager.removeView(view);
}

Post a Comment for "Is There A Way To Check If Android Windowmanager Already Contains A View?"