android.view.WindowLeaked:Activity has leaked window [email protected][] that was originally added h
程序员文章站
2022-04-01 15:51:04
...
E/WindowManager: android.view.WindowLeaked: Activity com.activity.LoginActivity has leaked window [email protected][] that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:428)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:337)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:94)
at android.app.Dialog.show(Dialog.java:332)
看提示是窗口泄露。
错误原因是因为activity中的Dialog、PopupWindow不能脱离activity而单独存在。当Dialog、PopupWindow正在显示的时候而它们依附的activity却destroy了,就会出现WindowLeaked异常。
解决办法是在finish 某个activity之前要确保依附于其上的Dialog、PopupWindow已经dismiss了
@Override
protected void onDestroy() {
super.onDestroy();
if(progressDialog!=null&&progressDialog.isShowing()) {
progressDialog.dismiss();
}
}
也可在OnCreateDialog()中创建Dialog,让系统去管理对话框。