Popupwindow leak window

08-16 10:07:51.410: ERROR/WindowManager(4236): Activity cn.bookall.android.zbook.reader.DocReader has l eaked window android.widget.TextView@485348b0 that was originally added here
08-16 10:07:51.410: ERROR/WindowManager(4236): android.view.WindowLeaked: Activity cn.bookall.android.zbook.reader.DocReader has leaked window android.widget.TextView@485348b0 that was originally added here
08-16 10:07:51.410: ERROR/WindowManager(4236):     at android.view.ViewRoot.<init>(ViewRoot.java:247)
...

08-16 10:07:51.410: ERROR/WindowManager(4236):     at cn.bookall.android.zbook.reader.DocView.ShowPopWindowCenter(DocView.java:506)

...

08-16 10:07:51.600: ERROR/AndroidRuntime(4236): java.lang.IllegalArgumentException:View not attached to window manager


按字面了解,Window Leaked大概就是说一个窗体泄漏了,也就是我们常说的内存泄漏,为什么窗体会泄漏呢?

产生原因:
我们知道Android的每一个Activity都有个WindowManager窗体管理器,同样,构建在某个Activity之上的对话框、PopupWindow也有相应的WindowManager窗体管理器。因为对话框、PopupWindown不能脱离Activity而单独存在着,所以当某个Dialog或者某个PopupWindow正在显示的时候我们去finish()了承载该Dialog(或PopupWindow)的Activity时,就会抛Window Leaked异常了,因为这个Dialog(或PopupWindow)的WindowManager已经没有谁可以附属了,所以它的窗体管理器已经泄漏了。


解决方法:
关闭(finish)某个Activity前,要确保附属在上面的Dialog或PopupWindow已经关闭(dismiss)了。

       @Override 
      public void onPause(){
         super.onPause();
         if(pw != null) {
              pw.dismiss(); 
         }
      } 

http://blog.csdn.net/u_xtian/article/details/6123945

http://www.eoeandroid.com/thread-30137-1-1.html

你可能感兴趣的:(android,manager,null,dialog,leak)