Android | 那些年踩过的坑之bug锦集

2018-11-23  本文已影响0人  l王小一

1.窗体泄露

报错信息

E/WindowManager: android.view.WindowLeaked: Activity com.yoyo.ipctest.MainActivity has leaked window DecorView@571161f[] that was originally added here
 
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:418)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:331)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:93)
at android.app.Dialog.show(Dialog.java:329)
at android.app.AlertDialog$Builder.show(AlertDialog.java:1112)
at com.yoyo.ipctest.MainActivity.releaseConnect(MainActivity.java:795)
at com.yoyo.ipctest.MainActivity.onDestroy(MainActivity.java:1385)
at android.app.Activity.performDestroy(Activity.java:6884)
at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1153)
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4191)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4222)
at android.app.ActivityThread.-wrap6(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1539)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6121)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)发生

发生窗体泄露的原因:
在当前activity中弹框后, 弹框没有关闭的时候就销毁了activity. 因为dialog是依附于activity显示的,所以当activity被销毁时就会造成窗体泄露. 就是上述报错信息

解决办法:
在activity被销毁时对dialog进行判断, 关闭当前已弹出的弹框

上一篇下一篇

猜你喜欢

热点阅读