Home » Android » android – View not attached to window manager (whats the solution?)

android – View not attached to window manager (whats the solution?)

Posted by: admin June 15, 2020 Leave a comment

Questions:

I got hundreads of error reports from my app and all of them is the same. It is really annoying because in my test devices (HTC Wildfire, Galaxy S I-II-III, Galaxy Mini, Galaxy Tab 10) this error NEVER occured, neither to me or my test buddy, looks like users do something different then us.

Because of this i cant give you too much information about the situation, there is one thing i see, it is something with a dialog’s dismiss, which i actually never calls by code.

here is the error:

java.lang.IllegalArgumentException: View not attached to window manager
at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:587)
at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:324)
at android.view.WindowManagerImpl$CompatModeWrapper.removeView(WindowManagerImpl.java:151)
at android.app.Dialog.dismissDialog(Dialog.java:328)
at android.app.Dialog$1.run(Dialog.java:119)
at android.app.Dialog.dismiss(Dialog.java:313)
at android.app.Dialog.cancel(Dialog.java:1113)
at hu.kulcssoft.ingyenkonyv.reader.Reader$JavaScriptInterface$1.run(Reader.java:199)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)

Can somebody help me? I got 30-40 error reports weekly because of this issue and i really cannot figure out why this is happening.

All suggestions will be appreciated. Thanks,

How to&Answers:

Dismiss the dialog in your onFinish or onDestroy of the launching activity.

Or/And

Don’t let your activity handle the orientation changes.

You might find some help in these answers :
java.lang.IllegalArgumentException: View not attached to window manager

Answer:

 @Override
            public void onConfigurationChanged(Configuration newConfig) {
                // TODO Auto-generated method stub
                super.onConfigurationChanged(newConfig);
                YourProgressDialog.dismiss();
            }

and Similarly you can use it on the onFinsh() and OnDestroy() or OnBackPressed() of the activity Depending on the Context of error.