PopupMenu PopupWindow $ PopupViewContainer泄漏 [英] PopupMenu PopupWindow$PopupViewContainer leak

查看:120
本文介绍了PopupMenu PopupWindow $ PopupViewContainer泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PopupMenu固定在操作栏中的按钮上,并且我正在获取有关泄漏窗口的日志输出.

I have a PopupMenu anchored to a button in the Action Bar, and I'm getting log output about a leaked window.

如果在打开PopupMenu时我的活动停止了,就会发生这种情况.

This occurs if my activity is stopped while the PopupMenu is open.

我在此处发布了一个相关问题,但我已经解决了该问题.

I posted a related question here, but I've solved that issue.

我已经看到了一些类似的问题,例如,但都没有与PopupMenu相关的问题.

I've seen some similar questions, like this, but none related to PopupMenu.

我正在考虑是否可以处理上述PopupWindow$PopupViewContainer的句柄,然后可以在onPause或类似的过程中将其从WindowManager中删除,但我不知道该怎么做. PopupMenu公开的界面非常有限.

I'm thinking if I can get a handle on the mentioned PopupWindow$PopupViewContainer then I could remove it from the WindowManager during onPause or something like that, but I don't know how to get at it. The interface exposed by PopupMenu is pretty limited.

  • 有人遇到过这个问题吗?
  • 有人修复或解决了这个问题吗?
  • 有人知道如何获取PopupMenuViewWindow吗?
  • Has anyone encountered this issue?
  • Has anyone fixed it or worked around it?
  • Anybody know how to get the PopupMenu's View or Window?

这是我创建菜单的方式:

This is how I create the menu:

// in Activity
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    final MenuInflater inflater = getMenuInflater();

    inflater.inflate(R.menu.main_menu, menu);
    MenuItem login = menu.findItem(R.id.menu_login);
    final Button button = (Button) login.getActionView().findViewById(R.id.login);

    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View item) {
            if (profileMenu == null) {
                // I've tried passing getApplicationContext() here too, with no change
                profileMenu = new PopupMenu(ListActivity.this, button);
                profileMenu.getMenuInflater().inflate(R.menu.profile_menu, profileMenu.getMenu());
                profileMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                    public boolean onMenuItemClick(MenuItem item) {
                        // there was code here, but I removed it and problem persists
                        return false;
                    }
                });
            }
            profileMenu.show();

        }
    });

这是完整的堆栈跟踪:

10-24 11:10:13.878: E/WindowManager(2048): Activity **.app.ListActivity has leaked window android.widget.PopupWindow$PopupViewContainer@4157a7e8 that was originally added here
10-24 11:10:13.878: E/WindowManager(2048): android.view.WindowLeaked: Activity **.app.ListActivity has leaked window android.widget.PopupWindow$PopupViewContainer@4157a7e8 that was originally added here
10-24 11:10:13.878: E/WindowManager(2048):  at android.view.ViewRootImpl.<init>(ViewRootImpl.java:374)
10-24 11:10:13.878: E/WindowManager(2048):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:292)
10-24 11:10:13.878: E/WindowManager(2048):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224)
10-24 11:10:13.878: E/WindowManager(2048):  at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149)
10-24 11:10:13.878: E/WindowManager(2048):  at android.widget.PopupWindow.invokePopup(PopupWindow.java:988)
10-24 11:10:13.878: E/WindowManager(2048):  at android.widget.PopupWindow.showAsDropDown(PopupWindow.java:897)
10-24 11:10:13.878: E/WindowManager(2048):  at android.widget.ListPopupWindow.show(ListPopupWindow.java:595)
10-24 11:10:13.878: E/WindowManager(2048):  at com.android.internal.view.menu.MenuPopupHelper.tryShow(MenuPopupHelper.java:127)
10-24 11:10:13.878: E/WindowManager(2048):  at com.android.internal.view.menu.MenuPopupHelper.show(MenuPopupHelper.java:100)
10-24 11:10:13.878: E/WindowManager(2048):  at android.widget.PopupMenu.show(PopupMenu.java:108)
10-24 11:10:13.878: E/WindowManager(2048):  at **.app.ListActivity$3.onClick(ListActivity.java:376)
10-24 11:10:13.878: E/WindowManager(2048):  at android.view.View.performClick(View.java:4084)
10-24 11:10:13.878: E/WindowManager(2048):  at android.view.View$PerformClick.run(View.java:16966)
10-24 11:10:13.878: E/WindowManager(2048):  at android.os.Handler.handleCallback(Handler.java:615)
10-24 11:10:13.878: E/WindowManager(2048):  at android.os.Handler.dispatchMessage(Handler.java:92)
10-24 11:10:13.878: E/WindowManager(2048):  at android.os.Looper.loop(Looper.java:137)
10-24 11:10:13.878: E/WindowManager(2048):  at android.app.ActivityThread.main(ActivityThread.java:4745)
10-24 11:10:13.878: E/WindowManager(2048):  at java.lang.reflect.Method.invokeNative(Native Method)
10-24 11:10:13.878: E/WindowManager(2048):  at java.lang.reflect.Method.invoke(Method.java:511)
10-24 11:10:13.878: E/WindowManager(2048):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
10-24 11:10:13.878: E/WindowManager(2048):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-24 11:10:13.878: E/WindowManager(2048):  at dalvik.system.NativeStart.main(Native Method)

推荐答案

仅在onStop()上调用profileMenu.dismiss()就足够了.

Simply calling profileMenu.dismiss() onStop() would be enough.

这篇关于PopupMenu PopupWindow $ PopupViewContainer泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆