I want to create a static options menu for all my activity screens. I dont want to override onCreateOptionsMenu() in each activity.
Since Menu class is an interface with a huge number of methods, its difficult to create a static object of the implementing class.
Any other way of doing the same?
If I read your question correctly you want the same menu in all your Activities. I can think of two ways to do this:
Create a subclass of
Activitythat implementsonCreateOptionsMenu()andonOptionsItemSelected()(and possiblyonPrepareOptionsMenu). Then have all yourActivityclasses extend this subclass.Create a static method somewhere called something like
populateOptionsMenu()that takes aMenu(and probably aContext) as arguments. YourActivityclasses can then call this from theironCreateOptionsMenu()methods to populate theMenu. You’d also need a correspondingprocessItemSelected()static method for when items were clicked.Option 1 seems best as it wouldn’t require the same bolierplate in your Activities to call the static methods.