Fix leak for MenuInflater + setSupportActionBar

Caused when there are multiple calls to
setSupportActionBar(). getMenuInflater() will
instantiate and keep an instance to the first
Toolbar (and it's container, etc).

BUG: 21638877
Change-Id: I4c79b4832534b06e7ab2819e78e303dde4a7d76a
diff --git a/v7/appcompat/src/android/support/v7/app/AppCompatDelegateImplBase.java b/v7/appcompat/src/android/support/v7/app/AppCompatDelegateImplBase.java
index 411f17c..316256c 100644
--- a/v7/appcompat/src/android/support/v7/app/AppCompatDelegateImplBase.java
+++ b/v7/appcompat/src/android/support/v7/app/AppCompatDelegateImplBase.java
@@ -43,7 +43,7 @@
     final AppCompatCallback mAppCompatCallback;
 
     ActionBar mActionBar;
-    private MenuInflater mMenuInflater;
+    MenuInflater mMenuInflater;
 
     // true if this activity has an action bar.
     boolean mHasActionBar;
@@ -93,14 +93,13 @@
         return mActionBar;
     }
 
-    final void setSupportActionBar(ActionBar actionBar) {
-        mActionBar = actionBar;
-    }
-
     @Override
     public MenuInflater getMenuInflater() {
+        // Make sure that action views can get an appropriate theme.
         if (mMenuInflater == null) {
-            mMenuInflater = new SupportMenuInflater(getActionBarThemedContext());
+            initWindowDecorActionBar();
+            mMenuInflater = new SupportMenuInflater(
+                    mActionBar != null ? mActionBar.getThemedContext() : mContext);
         }
         return mMenuInflater;
     }
diff --git a/v7/appcompat/src/android/support/v7/app/AppCompatDelegateImplV7.java b/v7/appcompat/src/android/support/v7/app/AppCompatDelegateImplV7.java
index 2f0d5af..e66d002 100644
--- a/v7/appcompat/src/android/support/v7/app/AppCompatDelegateImplV7.java
+++ b/v7/appcompat/src/android/support/v7/app/AppCompatDelegateImplV7.java
@@ -198,10 +198,12 @@
                     "by the window decor. Do not request Window.FEATURE_ACTION_BAR and set " +
                     "windowActionBar to false in your theme to use a Toolbar instead.");
         }
+        // Clear out the MenuInflater to make sure that it is valid for the new Action Bar
+        mMenuInflater = null;
 
         ToolbarActionBar tbab = new ToolbarActionBar(toolbar, ((Activity) mContext).getTitle(),
                 mAppCompatWindowCallback);
-        setSupportActionBar(tbab);
+        mActionBar = tbab;
         mWindow.setCallback(tbab.getWrappedWindowCallback());
         tbab.invalidateOptionsMenu();
     }