@@ -65,6 +65,7 @@ public class MenuInflater {
6565 private final Object [] mActionProviderConstructorArguments ;
6666
6767 private Context mContext ;
68+ private Object mRealOwner ;
6869
6970 /**
7071 * Constructs a menu inflater.
@@ -73,6 +74,20 @@ public class MenuInflater {
7374 */
7475 public MenuInflater (Context context ) {
7576 mContext = context ;
77+ mRealOwner = context ;
78+ mActionViewConstructorArguments = new Object [] {context };
79+ mActionProviderConstructorArguments = mActionViewConstructorArguments ;
80+ }
81+
82+ /**
83+ * Constructs a menu inflater.
84+ *
85+ * @see Activity#getMenuInflater()
86+ * @hide
87+ */
88+ public MenuInflater (Context context , Object realOwner ) {
89+ mContext = context ;
90+ mRealOwner = realOwner ;
7691 mActionViewConstructorArguments = new Object [] {context };
7792 mActionProviderConstructorArguments = mActionViewConstructorArguments ;
7893 }
@@ -190,12 +205,12 @@ private static class InflatedOnMenuItemClickListener
190205 implements MenuItem .OnMenuItemClickListener {
191206 private static final Class <?>[] PARAM_TYPES = new Class [] { MenuItem .class };
192207
193- private Context mContext ;
208+ private Object mRealOwner ;
194209 private Method mMethod ;
195210
196- public InflatedOnMenuItemClickListener (Context context , String methodName ) {
197- mContext = context ;
198- Class <?> c = context .getClass ();
211+ public InflatedOnMenuItemClickListener (Object realOwner , String methodName ) {
212+ mRealOwner = realOwner ;
213+ Class <?> c = realOwner .getClass ();
199214 try {
200215 mMethod = c .getMethod (methodName , PARAM_TYPES );
201216 } catch (Exception e ) {
@@ -210,9 +225,9 @@ public InflatedOnMenuItemClickListener(Context context, String methodName) {
210225 public boolean onMenuItemClick (MenuItem item ) {
211226 try {
212227 if (mMethod .getReturnType () == Boolean .TYPE ) {
213- return (Boolean ) mMethod .invoke (mContext , item );
228+ return (Boolean ) mMethod .invoke (mRealOwner , item );
214229 } else {
215- mMethod .invoke (mContext , item );
230+ mMethod .invoke (mRealOwner , item );
216231 return true ;
217232 }
218233 } catch (Exception e ) {
@@ -400,7 +415,7 @@ private void setItem(MenuItem item) {
400415 + "be used within a restricted context" );
401416 }
402417 item .setOnMenuItemClickListener (
403- new InflatedOnMenuItemClickListener (mContext , itemListenerMethodName ));
418+ new InflatedOnMenuItemClickListener (mRealOwner , itemListenerMethodName ));
404419 }
405420
406421 if (item instanceof MenuItemImpl ) {
0 commit comments