博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

How WindowLeaked exception occured?

Posted on 2014-07-15 13:09  haobo  阅读(246)  评论(0编辑  收藏  举报

If a Activity performDestroy, and there is window not closed whose window token is the Activity's mWindow, WindowLeaked exception will occur.

Especially, app adds a view to WindowManager, when the app come across a crash, and if the app not remove the view from WindowManager at Activity's onDestory() callback funtion, the WindowLeaked exception occurs.

When an app come across an exception, the activity will performStop() first, in this function, will callback mWindow's closeAllPanels() which will close all menus window. And then, activity will performDestory(), in this function will call WindowManagerGlobal's closeAll() function, if there is any window associate with the activity's mWindow, close it and report a WindowLeak.

So, to avoid this. You should make sure to remove all views added to WindowManager before the activity be destroyed.

By the way, WindowManager's removeView() and removeViewImmediate is different. The later will cause a immediate remove.