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 :)
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With