OptionMenu for the entire Android app?

I can create an options menu for one action. But now I want to create the "Exit" option in the menu, which should be available in all actions in the application. Is there a way to create an Option menu once for an application?

+4
source share
1 answer

I answered once on SO, but I forgot where ... so here I go again.

Its pretty straightforward.

Create BaseActivity (extends Activity ). Enter in this code all the codes of the parameter menu. Override onOptionsMenu etc.

Now, for all of your other actions, instead of extending the action, BaseActivity . As a result, you will get the code for the options menu ... nifty eh?

Code once, use several times ...

OOP for victory!

Edit: As WarrenFaith points out, you need to create BaseListActivity and BaseMapActivity if you use ListActivity and MapActivity .

+11
source

All Articles