这里泄漏了什么,我不明白。
06-07 17:04:50.319: E/WindowManager(23232): Activity com.test.MainActivity has leaked window android.widget.LinearLayout@41ab4238 that was originally added here
06-07 17:04:50.319: E/WindowManager(23232): android.view.WindowLeaked: Activity com.test.MainActivity has leaked window android.widget.LinearLayout@41ab4238 that was originally added here
06-07 17:04:50.319: E/WindowManager(23232): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:403)
06-07 17:04:50.319: E/WindowManager(23232): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:267)
06-07 17:04:50.319: E/WindowManager(23232): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:215)
06-07 17:04:50.319: E/WindowManager(23232): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:140)
06-07 17:04:50.319: E/WindowManager(23232): at android.view.Window$LocalWindowManager.addView(Window.java:537)
06-07 17:04:50.319: E/WindowManager(23232): at android.widget.PopupWindow.invokePopup(PopupWindow.java:992)
06-07 17:04:50.319: E/WindowManager(23232): at android.widget.PopupWindow.showAsDropDown(PopupWindow.java:901)
06-07 17:04:50.319: E/WindowManager(23232): at com.test.MainActivity.onClick(MainActivity.java:91)
我的代码如下
活动课
@Override
public void onClick(View v) {
LayoutInflater layoutInflater = (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popup, null);
popupWindow = new SettingsPopupWindow(popupView, 150, 300);
popupWindow.showAsDropDown(btnOpenPopup, 0, 0);
}
protected void initMenuButtonPopup()
{
btnOpenPopup = (Button)findViewById(R.id.menuButton);
btnOpenPopup.setOnClickListener(this);
}
弹出类
public class SettingsPopupWindow extends PopupWindow implements OnClickListener{
View vw;
@Override
public void onClick(View v) {
dismiss();
}
public SettingsPopupWindow(View contentView, int width, int height)
{
super(contentView, width, height);
this.vw = contentView;
Button btnDismiss = (Button)vw.findViewById(R.id.dismiss);
btnDismiss.setOnClickListener(this);
}
}