问题虽小,不过不知道还是比较麻烦的。异常信息:
10-22 10:19:38.651 12723-12723/cn.com.zte.uc E/WindowManager﹕ android.view.WindowLeaked: Activity cn.com.zte.uc.activites.shipTicket.OrderWrite1 has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{423fee70 V.E..... R......D 0,0-455,230} that was originally added here at android.view.ViewRootImpl.<init>(ViewRootImpl.java:364) at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:258) at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69) at android.app.Dialog.show(Dialog.java:289) at cn.com.zte.uc.activites.BaseActivity.showInProgress(BaseActivity.java:147) at cn.com.zte.uc.activites.shipTicket.OrderWrite1.onClick(OrderWrite1.java:135) at android.view.View.performClick(View.java:4446) at android.view.View$PerformClick.run(View.java:18485) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5262) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:851) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:667) at dalvik.system.NativeStart.main(Native Method)
直接从项目里面拷贝出来的,出错代码为show一个ProgressDialog。还有一种情况就是ProgressDialog还在显示的时候,finish activity也会出现。
原因分析:
Android的每一个Activity都有个WindowManager窗体管理器,同样,构建在某个Activity之上的对话框、PopupWindow也有相应的WindowManager窗体管理器。因为对话框、PopupWindown不能脱离Activity而单独存在着,所以当某个Dialog或者某个PopupWindow正在显示的时候我们去finish()了承载该Dialog(或PopupWindow)的Activity时,就会抛Window
Leaked异常了,因为这个Dialog(或PopupWindow)的WindowManager已经没有谁可以附属了,所以它的窗体管理器已经泄漏了。
解决办法:
关闭(finish)某个Activity前,要确保附属在上面的Dialog或PopupWindow已经关闭(dismiss)了。
时间: 2024-10-09 08:27:52