I've seen several reports of issues where openOptionsMenu() will not work on various Android versions, eg:
openOptionsMenu() across android versions
but the issue I have seems to be related to the version of the appcompat-v7 support library being used.
In essence, with the newer versions of appcompat-v7 the menu will appear fine when openOptionsMenu() is called if your activity extends Activity but will not work if you extend ActionBarActivity or AppCompatActivity (ie use the compatibility library). In older versions of appcompat-v7 it works fine.
It is reproducible, as follows:
- In Android Studio, Import Sample 'ActionBarCompat-Basic'
- Add a button to the screen, which invokes openOptionsMenu()
- Note that this works fine, as the old version of the library, appcompat-v7:21.0.3 is used in the sample
- Change the dependency to use appcompat-v7:23.0.1, rebuild, and when clicking on the button the menu will not appear.
- Change the main activity to extend Activity (ie no app compatability) - it works
- Change the main activity to extend AppCompatActivity (ie using app compatibility libarry) - it fails
After some testing, I've found that this stopped working in appcompat-v7:22.1.0, and will no longer work in any newer version of this jar.
This behaviour is identical on the emulator and on a physical device, and on Android versions 5.1.1(23) and 2.1(7) which were the two versions I tested it with.
I've added a comment to this bug: Android issue tracker bug
Any suggestions, ideas or workarounds appreciated!
-Steve