When using dialog, the following two errors are not shown
12-11 17:47:49.776:e/windowmanager (11461): android.view.WindowLeaked:Activity testactivity has leaked window com.android.internal.policy.impl.phonewindow$decorview{42204800 v.e ..... R..... I. 0,0-640,164} that is originally added here
12-11 17:47:50.666:e/androidruntime (11461): java.lang.illegalargumentexception:view= com.android.internal.policy.impl.phonewindow$decorview{42204800 v.e ..... R..... I. 0,0-640,164} not attached to Window manager
The reason: thedialog life cycle is longer than the activity's life cycle
So, when this bug occurs, check to see if the activity that created the dialog context is over, and dialog is still showing.
The following test code can reproduce the above mentioned bug
Public class extends activity{ private Dialog mdialog; @Override publicvoid onCreate (Bundle savedinstancestate) { Super. OnCreate (savedinstancestate); Setcontentview (r.layout.activity_test); New Dialog (this); Mdialog.show (); Finish (); // The immediate end of the activity, when the dialog is not closed, still showing that the life cycle is longer than the activity, there will be the above mentioned bug}
Workaround:
1. Please check if you have not yet waited for the dialog to disappear before ending the activity. If it is, you must have a problem with your logic and end the activity without waiting for the dialog to finish.
2. In any case, when the activity is over, you are sure to close the dialog. Then you can close the dialog in OnStop or OnPause.
@Override protected void OnStop () { super. OnStop (); if (Mdialog.isshowing ()) { Mdialog.dismiss (); }}
Decorview that is originally added here or Java.lang.IllegalArgumentException:View not attached to window manager