IT培训网 - IT职场人学IT技术上IT培训网
android.view.WindowLeaked的解决方法
时间:2016-10-14 16:57:15 来源:Android培训网 作者:IT培训网 已有:名学员访问该课程
本文由IT培训网编辑
虽然是小问题一个,但也困扰了我一段时间,现在记下来,给自己做个备忘,也可以给其他人一个参考
- 1.01-08 01:49:27.874: ERROR/WindowManager(473): Activity com.photos.MainActivity has leaked window android.widget.ImageButton@43e40d10 that was originally added here
- 2.01-08 01:49:27.874: ERROR/WindowManager(473): android.view.WindowLeaked: Activity com.photos.MainActivity has leaked window android.widget.ImageButton@43e40d10 that was originally added here
- 3.01-08 01:49:27.874: ERROR/WindowManager(473): at android.view.ViewRoot.<init>(ViewRoot.java:247)
- 4.01-08 01:49:27.874: ERROR/WindowManager(473): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
- 5.01-08 01:49:27.874: ERROR/WindowManager(473): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
- 6.01-08 01:49:27.874: ERROR/WindowManager(473): at android.view.Window$LocalWindowManager.addView(Window.java:424)
- 7.01-08 01:49:27.874: ERROR/WindowManager(473): at android.widget.PopupWindow.invokePopup(PopupWindow.java:828)
- 8.01-08 01:49:27.874: ERROR/WindowManager(473): at android.widget.PopupWindow.showAtLocation(PopupWindow.java:688)
- 9.01-08 01:49:27.874: ERROR/WindowManager(473): at com.photos.MainActivity.showCommonPopup(MainActivity.java:256)
- 10.01-08 01:49:27.874: ERROR/WindowManager(473): at com.photos.MainActivity.access$3(MainActivity.java:255)
- 11.01-08 01:49:27.874: ERROR/WindowManager(473): at com.photos.MainActivity$2.handleMessage(MainActivity.java:88)
- 12.01-08 01:49:27.874: ERROR/WindowManager(473): at android.os.Handler.dispatchMessage(Handler.java:99)
- 13.01-08 01:49:27.874: ERROR/WindowManager(473): at android.os.Looper.loop(Looper.java:123)
- 14.01-08 01:49:27.874: ERROR/WindowManager(473): at android.app.ActivityThread.main(ActivityThread.java:4627)
- 15.01-08 01:49:27.874: ERROR/WindowManager(473): at java.lang.reflect.Method.invokeNative(Native Method)
- 16.01-08 01:49:27.874: ERROR/WindowManager(473): at java.lang.reflect.Method.invoke(Method.java:521)
- 17.01-08 01:49:27.874: ERROR/WindowManager(473): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
- 18.01-08 01:49:27.874: ERROR/WindowManager(473): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
- 19.01-08 01:49:27.874: ERROR/WindowManager(473): at dalvik.system.NativeStart.main(Native Method)
产生原因:
我们知道Android的每一个Activity都有个WindowManager窗体管理器,同样,构建在某个Activity之上的对话框、PopupWindow也有相应的WindowManager窗体管理器。因为对话框、PopupWindown不能脱离Activity而单独存在着,所以当某个Dialog或者某个PopupWindow正在显示的时候我们去finish()了承载该Dialog(或PopupWindow)的Activity时,就会抛Window Leaked异常了,因为这个Dialog(或PopupWindow)的WindowManager已经没有谁可以附属了,所以它的窗体管理器已经泄漏了。
解决方法:
关闭(finish)某个Activity前,要确保附属在上面的Dialog或PopupWindow已经关闭(dismiss)了。
IT培训网是IT培训网教育旗下培训网站。IT培训网依托中国互联网行业蓬勃发展优势,为中国的软件开发学习者和IT从业人员提供培训学校、编程学习、经验交流、咨询解答等服务,帮助更多喜爱编程的人员实现自己的IT梦想。
每期开班座位有限.0元试听抢座开始!
温馨提示 : 请保持手机畅通,咨询老师为您
提供专属一对一报名服务。
- 上一篇:Android坐标系、视图坐标系与触控事件
- 下一篇:Android内存优化