Best practices for the Android action bar

I am new to this and quite new to Android development, and have already developed some bad habits.

I basically encoded the application using the old training source as a link that did not cover the fragments. Thus, I have several standard actions that I do in the process of converting to fragments.

One thing I have not been able to find information on is the best practices for the action bar; is it best to identify the action bar in activity or in fragment?

I notice that calling onCreateOptionsMenu (menu menu, inflatable MenuInflater element) leads to minor changes when calling the same method in action, can I get any tips on where to best name it and what benefits it provides?

thanks

+4
source share
1 answer

Yes, this method is slightly different for the snippet:

void onCreateOptionsMenu(Menu menu, MenuInflater inflater)

and activity:

boolean onCreateOptionsMenu(Menu menu)

The logic is quite simple: if you have the same action panel (as many actions) for all fragments, it is better to define it in action. If the Action Bar layout depends on the fragment, it is better to define it there.

0
source

All Articles