Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Shared menu between activities

I need to create an application that have a shared menu between all activities, but I hesitate between creating the same menu for all activities and make these activities 'singletones', or create multiple fragments and use them in one activity that will have the menu.

I want to make my application compatible with most devices, so I don't know which one is the best (for memory management and reusable stuffs ...)

What should I try ? if is there a better process than these two, feel free to suggest :)

like image 879
Mehdi Avatar asked Aug 05 '26 21:08

Mehdi


1 Answers

One way to do it is to define a parent class activity that all other activities will inherit from. In the parent's class onCreateOptionsMenu you define the menu that is common for all activities:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.common_menu, menu);
    return true;
}
like image 173
Szymon Avatar answered Aug 07 '26 09:08

Szymon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!