I create an app that supports both phone and tablet version so i use the android-support-v4.jar library. My activity extends the FragmentActivity and override the onCreateOptionsMenu(Menu menu). This works fine on tablet, the onCreateOptionsMenu being called correctly but it doesn't work on phone, onCreateOptionsMenu never get called. How to resolve this?
Note: i use <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="12"/>
on Manifest file.
If you've developed for Android 3.0 and higher, the system calls onCreateOptionsMenu() when starting the activity, in order to show items to the app bar.
Find the onCreateOptionsMenu(Menu menu) method which needs to override in Activity class. This creates menu and returns Boolean value. inflate inflates a menu hierarchy from XML resource.
In case of ICS and Honeycomb onCreateOptionsMenu() is called after onCreate() and onPostCreate() while in Gingerbread and earlier versions it is called after onCreate() but before onPostCreate() . Save this answer.
A FragmentActivity is a subclass of Activity that was built for the Android Support Package. The FragmentActivity class adds a couple new methods to ensure compatibility with older versions of Android, but other than that, there really isn't much of a difference between the two.
You should consider from your Fragment
code:
1) Implementing onCreateOptionsMenu(Menu menu, MenuInflater inflater)
2) Calling setHasOptionsMenu
3) And also implementing onOptionsItemSelected(MenuItem item)
Then you will be ok on both the phone and tablet.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With