Solutions to Android.view.WindowLeaked

Source: Internet
Author: User

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

Related Article

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.