Solutions for android.view.WindowLeaked (form disclosure)

Source: Internet
Author: User

Although it is a small problem, but also troubled me for a while, now write down, give yourself a memo, also can give other people a reference

Java code
  1. View Plaincopy to Clipboardprint?
  2. 01-: 27.874:error/windowmanager (473): Activity com.photos.MainActivity has leaked window Android.widget.ImageButton@43e40d10 that is originally added here
  3. 01-: 27.874:error/windowmanager (473): android.view.WindowLeaked:Activity Com.photos.MainActivity have leaked window Android.widget.ImageButton@43e40d10 that is originally added here /c5>
  4. 01-: 27.874:error/windowmanager (473): At Android.view.viewroot.<init> ( Viewroot.java:247)
  5. 01-: 27.874:error/windowmanager (473): At Android.view.WindowManagerImpl.addView ( Windowmanagerimpl.java:148)
  6. 01-: 27.874:error/windowmanager (473): At Android.view.WindowManagerImpl.addView ( Windowmanagerimpl.java: ()
  7. 01-: 27.874:error/windowmanager (473): at android.view.window$ Localwindowmanager.addview (Window.java:424)
  8. 01-: 27.874:error/windowmanager (473): At Android.widget.PopupWindow.invokePopup ( Popupwindow.java:828)
  9. 01-: 27.874:error/windowmanager (473): At Android.widget.PopupWindow.showAtLocation ( Popupwindow.java:688)
  10. 01-: 27.874:error/windowmanager (473): At Com.photos.MainActivity.showCommonPopup ( Mainactivity.java:)
  11. 01-: 27.874:error/windowmanager (473): At com.photos.mainactivity.access$3 ( Mainactivity.java:255)
  12. 01-: 27.874:error/windowmanager (473): at com.photos.mainactivity$2. Handlemessage (Mainactivity.java:)
  13. 01-: 27.874:error/windowmanager (473): At Android.os.Handler.dispatchMessage ( Handler.java:)
  14. 01-: 27.874:error/windowmanager (473): At Android.os.Looper.loop (Looper.java: 123)
  15. 01-: 27.874:error/windowmanager (473): At Android.app.ActivityThread.main ( Activitythread.java:4627)
  16. 01-: 27.874:error/windowmanager (473): At Java.lang.reflect.Method.invokeNative ( Native Method)
  17. 01-: 27.874:error/windowmanager (473): At Java.lang.reflect.Method.invoke (Method.java: 521)
  18. 01-: 27.874:error/windowmanager (473): at com.android.internal.os.zygoteinit$ Methodandargscaller.run (Zygoteinit.java:868)
  19. 01-: 27.874:error/windowmanager (473): At Com.android.internal.os.ZygoteInit.main ( Zygoteinit.java:626)
  20. 01-: 27.874:error/windowmanager (473): At Dalvik.system.NativeStart.main (Native Method)


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.

Android.view.WindowLeaked typically occur in activity and dialog displays.

Activity in Create a dialog, if you first close dialog and then close activity is normal, if you first close activity and then close dialog will error this android.view.WindowLeaked errors.
The reason for this analysis is that dialog is created based on activity: New ProgressDialog, this is activity. Activtity first finish, that dialog will not have dependency, so will be reported android.view.WindowLeaked.




Workaround:
Before closing (finish) an activity, make sure that the dialog or popupwindow attached to it is closed (dismiss).
You can also create dialog in Oncreatedialog () to allow the system to manage dialog boxes

Solutions for android.view.WindowLeaked (form disclosure)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.