Take the 2-minute tour ×

I want to have an options menu that is available to all Activities in my app (on pressing the MENU button). I've been doing this by creating it in onCreateOptionsMenu(Menu menu) for each Activity but this seems redundant.

Is there a way to create it in one place and have it available in all Activities?

share|improve this question
add comment

3 Answers

up vote 7 down vote accepted

Subclass Activity to have your own activity class, and extend that to inherit some functionality like OptionsMenu.

share|improve this answer
For Example: stackoverflow.com/questions/4894116/… –  Jared Burrows Mar 17 '12 at 22:55
add comment

If your other class extends Activity then change it to extend the new OptionsMenuActivity class created by you. However if it extends one of the subclasses of Activity, such as ListActivity, MapActivity etc then I guess either you can either extend each of these subclasses with options menu functionality or simply repeat the options menu code for each Activity.

share|improve this answer
add comment

I've been trying to figure this out as well. Like what everyone else says, I've been extending Activity in a class called BaseActivity.

The annoyance with this is when your activity extends ListActivity or some other activity class then you also need to extend all those other activity classes as well.

There is a Java technology that I don't quite remember the name but is something similar to C's #define statement which allows for code injection.

share|improve this answer
add comment

Your Answer


