title: PopupMenu PopupWindow$PopupViewContainer leak
body: <p>I have a <code>PopupMenu</code> anchored to a button in the Action Bar, and I'm getting log output about a leaked window.</p>
  
  <p>This occurs if my activity is stopped while the <code>PopupMenu</code> is open. </p>
  
  <p>I posted a related question <a href="https://stackoverflow.com/q/13005150/931277">here</a>, but I've solved that issue.</p>
  
  <p>I've seen some similar questions, like <a href="https://stackoverflow.com/questions/5978069/cant-dismiss-popupwindow">this</a>, but none related to <code>PopupMenu</code>.</p>
  
  <p>I'm thinking if I can get a handle on the mentioned <code>PopupWindow$PopupViewContainer</code> then I could remove it from the <code>WindowManager</code> during onPause or something like that, but I don't know how to get at it.  The interface exposed by <code>PopupMenu</code> is pretty limited.</p>
  
  <ul>
  <li>Has anyone encountered this issue? </li>
  <li>Has anyone fixed it or worked around it? </li>
  <li>Anybody know how to get the <code>PopupMenu</code>'s <code>View</code> or <code>Window</code>?</li>
  </ul>
  
  <p>This is how I create the menu:</p>
  
  <pre><code>// 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();
  
          }
      });
  </code></pre>
  
  <p>Here is the full stack trace:</p>
  
  <pre><code>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.&lt;init&gt;(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)
  </code></pre>