I have a BaseActivity class that extends Activity, in it I have
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// draw menu stuff
}
Then I have other class that extend BaseActivity, such as
HelpActivity extends Activity
I thought that according to the rules of inheritance, it would automatically inherit BaseActivty’s onCreateOptionMenu call. It doesn’t, so I’m not sure why.
But anyway, in HelpActivity I added this:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return super.onCreateOptionsMenu(menu);
}
and THAT didn’t work either (ie no menu was displayed on Galaxy Nexus). So I literally copied and pasted BaseActivity’s onCreateOptionsMenu call into HelpActivity, and that worked. Why is this the case?
edit:
Two notes:
When I say it’s not working, I mean: I have a Galaxy Nexus, and the Menu doesn’t even get displayed on the ActionBar (ActionBarSherlock). When it works, I get the menu, including the menu ellipsis.
Secondly:
According to the Android docs:
Tip: If your application contains multiple activities and some of them
provide the same Options Menu, consider creating an activity that
implements nothing except the onCreateOptionsMenu() and
onOptionsItemSelected() methods. Then extend this class for each
activity that should share the same Options Menu. This way, you have
to manage only one set of code for handling menu actions and each
descendant class inherits the menu behaviors.
Got this from: Re-using Options menu code
According to what you have pasted your
HelpActivityis not extendingBaseActivity.HelpActivity extends Activity