Skip to content

Instantly share code, notes, and snippets.

@HIREN4131KINAL
Created June 6, 2017 13:54
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save HIREN4131KINAL/2c5bd249d546e5a243a04337dc28ae3b to your computer and use it in GitHub Desktop.
Proposal: On the android.view.WindowLeaked (window leak) solution
Abstract
According to the literal understanding, Window Leaked probably means a form of leakage, is what we often say that the memory leak, why the form will leak?
Background
The causes of:
We know that every Activity Android has an WindowManager window manager, likewise, is built on top of a Activity dialog box, PopupWindow also has the corresponding WindowManager window manager. Because the dialog box, the PopupWindown from the Activity and should not exist alone, So when a Dialog or a PopupWindow is displayed when we go to finish () carrying the Dialog (or PopupWindow) Activity, Window Leaked exception will be thrown., Because the Dialog (or PopupWindow) WindowManager have who can not affiliated., So the window manager it has leaked.
This error can be a little misleading in some circumstances (although the answer is still completely accurate) - i.e. in my case an unhandled Exception was thrown in an AsyncTask, which caused the Activity to shutdown, then an open progressdialog caused this Exception.. so the 'real' exception was a little earlier in the log
Android.view.WindowLeaked usually occur in the display of Activity and Dialog.
Create Activity in a Dialog, and if you turn off Dialog first and then close the Activity is normal, if you shut down the Activity first and then close the Dialog will error the error android.view.WindowLeaked.
Analysis the reason is: Dialog is created based on Activity: new ProgressDialog (this); this is Activity. Activtity finish first, then Dialog will have no attachment, so will report android.view.WindowLeaked.
Solution:
Close (finish) a Activity before, to ensure that the subsidiary in the above Dialog or PopupWindow have been closed (dismiss).
Is also available at OnCreateDialog (Dialog) to create, let the system to manage the dialog box
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment