android.view.WindowLeaked解决办法

时间:2022-07-16 16:22:11

08-07 14:51:28.129: E/WindowManager(22277): Activity com.xxx.xxx.xxx.xxx.LoginActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@416a4268 that was originally added here
08-07 14:51:28.129: E/WindowManager(22277): android.view.WindowLeaked: Activity com..xxx.xxx.xxx.xxx.LoginActivity has leaked windowcom.android.internal.policy.impl.PhoneWindow$DecorView@416a4268 that was originally added here
08-07 14:51:28.129: E/WindowManager(22277):  at android.view.ViewRootImpl.<init>(ViewRootImpl.java:344)
08-07 14:51:28.129: E/WindowManager(22277):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:267)
08-07 14:51:28.129: E/WindowManager(22277):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:215)
08-07 14:51:28.129: E/WindowManager(22277):  at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:140)
08-07 14:51:28.129: E/WindowManager(22277):  at android.view.Window$LocalWindowManager.addView(Window.java:537)
08-07 14:51:28.129: E/WindowManager(22277):  at android.app.Dialog.show(Dialog.java:278)
08-07 14:51:28.129: E/WindowManager(22277):  at com.xxx.xxx.xxx.xxx.BaseActivity.showMyProgressDialog(BaseActivity.java:1058)
08-07 14:51:28.129: E/WindowManager(22277):  at com.xxx.xxx.xxx.xxx.LoginActivity.setClickable(LoginActivity.java:580)
08-07 14:51:28.129: E/WindowManager(22277):  at com.xxx.xxx.xxx.xxx.LoginActivity.onClick(LoginActivity.java:482)
08-07 14:51:28.129: E/WindowManager(22277):  at android.view.View.performClick(View.java:3519)
08-07 14:51:28.129: E/WindowManager(22277):  at android.view.View$PerformClick.run(View.java:14140)
08-07 14:51:28.129: E/WindowManager(22277):  at android.os.Handler.handleCallback(Handler.java:605)
08-07 14:51:28.129: E/WindowManager(22277):  at android.os.Handler.dispatchMessage(Handler.java:92)
08-07 14:51:28.129: E/WindowManager(22277):  at android.os.Looper.loop(Looper.java:137)
08-07 14:51:28.129: E/WindowManager(22277):  at android.app.ActivityThread.main(ActivityThread.java:4424)
08-07 14:51:28.129: E/WindowManager(22277):  at java.lang.reflect.Method.invokeNative(Native Method)
08-07 14:51:28.129: E/WindowManager(22277):  at java.lang.reflect.Method.invoke(Method.java:511)
08-07 14:51:28.129: E/WindowManager(22277):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
08-07 14:51:28.129: E/WindowManager(22277):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
08-07 14:51:28.129: E/WindowManager(22277):  at dalvik.system.NativeStart.main(Native Method)

解决:好多人都说这个是内存泄漏  我自己也弄了好久 终于找到了原因 哈哈 其实不是什么内存泄漏 
原因是 activity 和dialog同时显示 要先dialog.dismiss() 后activity.finish() 如果直接finish() 会出错 但不影响功能。

这个问题属于当前Activity已经onDestroy但是依靠其的Dialog没有dismiss

if (progressDialog != null && progressDialog.isShowing())
{
     progressDialog.dismiss();
}

注意使用this.isFinishing()可能导致progressDialog取消不掉