android activity has leaked window com.android.internal.policy.impl.phonewindow$decorview Issue

后端 未结 8 797
再見小時候
再見小時候 2020-11-28 05:56

I am working with Android application to show network error.

NetErrorPage.java

package exp.app;

import android.app.Activity;
impor         


        
8条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-28 06:07

    Change this dialog.cancel(); to dialog.dismiss();

    The solution is to call dismiss() on the Dialog you created in NetErrorPage.java:114 before exiting the Activity, e.g. in onPause().

    Views have a reference to their parent Context (taken from constructor argument). If you leave an Activity without destroying Dialogs and other dynamically created Views, they still hold this reference to your Activity (if you created with this as Context: like new ProgressDialog(this)), so it cannot be collected by the GC, causing a memory leak.

提交回复
热议问题