Source:
Literally, window leaked is about a form leak, which is what we often say about memory leaks, why Windows leak?
Cause:
We know that every activity in Android has a WindowManager form manager, and similarly, a dialog box built on top of an activity, Popupwindow also has a corresponding WindowManager form manager. Because dialogs and Popupwindown cannot be separated from activity, we go to finish () to carry the dialog (or Popupwindow) when a dialog or a Popupwindow is being displayed. Activity, it will throw window leaked exception, because this dialog (or Popupwindow) WindowManager No one can be attached, so its form manager has been leaked.
Workaround:
Before closing (finish) an activity, make sure that the dialog or popupwindow attached to it is closed (dismiss).
Like what:
@Override protected void OnDestroy () { super. OnDestroy (); if NULL ) { Mdialog.dismiss (); } }
Learn:
If we declare dialog or Popupwindow in an activity, make sure the bodies are closed when the current activity is closed, otherwise it will cause window leaked
Solutions to Android.view.WindowLeaked