活动已泄漏窗口android.widget.PopupWindow API 27

时间:2018-09-20 07:14:47

标签: android android-layout

我有一个简单的活动,带有弹出菜单。

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu,menu);

    return super.onCreateOptionsMenu(menu);
}

当我打开菜单并旋转时,出现以下错误:

活动已泄漏窗口android.widget.PopupWindow

  

E / WindowManager:android.view.WindowLeaked:活动com.ehr.CompanyActivity已泄漏窗口android.widget.PopupWindow $ PopupDecorView {f8c5b6f VE ..... ...... ID 0,0-515,504}它最初是在android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:346)在android.view.WindowManagerImpl.addView(WindowManagerImpl.java:93)在android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:346)处添加的位于android.support.v7的android.widget.PopupWindow.showAsDropDown(PopupWindow.java:1284)的android.widget.PopupWindow.invokePopup(PopupWindow.java:1433)位于android.support.v7.widget.AppCompatPopupWindow.showAsDropDown(AppCompatPopupWindow.java:76) android.support.v7.widgetList上的.support.v4.widget.PopupWindowCompat $ PopupWindowCompatApi19Impl.showAsDropDown(PopupWindowCompat.java:115)位于android.support.v4.widget.PopupWindowCompat.showAsDropDown(PopupWindowCompat.java:219)。 (ListPopupWindow.java:733)在android.support.v7.view.menu.StandardMenuPopup.tryShow(StandardMenuPopup.jav a:176),位于android.support.v7.view.menu.StandardMenuPopup.show(StandardMenuPopup.java:203),位于android.support.v7.view.menu.MenuPopupHelper.showPopup(MenuPopupHelper.java:289) .v7.view.menu.MenuPopupHelper.tryShow(MenuPopupHelper.java:176)在android.support.v7.widget.ActionMenuPresenter $ OpenOverflowRunnable.run(ActionMenuPresenter.java:805)在android.os.Handler.handleCallback(Handler.java) :790)位于android.os.Handler.dispatchMessage(Handler.java:99),位于android.os.Looper.loop(Looper.java:164),位于android.app.ActivityThread.main(ActivityThread.java:6494),位于Java com.android.internal.os.RuntimeInit $ MethodAndArgsCaller.run(RuntimeInit.java:438)上的.lang.reflect.Method.invoke(本机方法)

我几乎没有写更多的通用代码。

1 个答案:

答案 0 :(得分:0)

问题是您已夸大菜单,但仍返回super.onCreateOptionsMenu(menu);。将返回值更改为true

@Override
public boolean onCreateOptionsMenu(Menu menu) {
     MenuInflater inflater = getMenuInflater();
     inflater.inflate(R.menu.menu,menu);

     return true;
}