Decorview that is originally added here or Java.lang.IllegalArgumentException:View not attached to window manager

Source: Internet
Author: User

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

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.