Android之Activity **** has leaked window android.widget.PopupWindow$PopupDecorView that was originall

1 问题

在页面实现了popupWindows,旋转屏幕的时候提示下面的错误

Activity **** has leaked window android.widget.PopupWindow$PopupDecorView that was originally added here

很明显,窗口内存泄漏,因为旋转屏幕的时候,依次会调用activity的onPause方法onStop方法onDestroy方法,当依附的activity销毁时,但是这个时候popupWindows句柄还在就会有这个问题

 

 

 

 

 

2 初步测试

在onDestroy方法里面关闭popupWindows

	@Override
	protected void onDestroy() {
		super.onDestroy();
		if (popupWindow != null && popupWindow.isShowing()) {
            		popupWindow.dismiss();
            	popupWindow = null;
        	}
	}

然后测试依然还是出现上面的错误,这不日了狗吗?

 

 

 

 

 

3 分析

Activity组件的应用程序窗口视图对象和ViewRoot对象关联通过窗口管理器(WindowManager)关联

1)  分析Window类getWindowManager方法

  public WindowManager getWindowManager() {
        return mWin

你可能感兴趣的:(Andriod,积累)