[Solved] onCreateOptionsMenu not called when starting new activity

My onCreateOptionsMenu works only in my MainActivity and when I try to put another onCreateOptionsMenu in another activity to inflate a different menu it does not display my menu bar (note that I have it setup exactly the same in both activities).

I do not get any errors, it just does not display my menu bar on my secondary activity.

Here is my code:

protected void onCreate(Bundle savedInstanceState){

public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(, menu);
    return true;

public boolean onOptionsItemSelected(MenuItem item) {
    //noinspection SimplifiableIfStatement
    int id = item.getItemId();
    if (id == {
    return super.onOptionsItemSelected(item);

Also note that I changed getMenuInflater() to super.getMenuInflater() and got same result.

Solution #1:

try adding method of super in your callback onCreateOptionsMenu implementation.

return super.onCreateOptionsMenu(menu);
Respondent: srv_sud

Solution #2:

In case you are using tool bar in your activity

public void onCreate(Bundle savedInstanceState) {
   mToolbar = (Toolbar) findViewById(;
Respondent: Mr.Q

Solution #3:

The problem in my case is if extend Activity, then onCreateOptionsMenu is not triggered. Did it manually with in onCreate:

Toolbar toolbar = findViewById(;

Of course, toolbar is defined in CoordinatorLayout



Solution #4:

don’t forget to call parent function like this

public boolean onCreateOptionsMenu(Menu menu) {
Respondent: baroni

Solution #5:

you should building a new xml menu (Second.xml).

public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(, menu);//Second es your new xml.
    return true;
Respondent: Slinker

Solution #6:

I was having the same problem: – I found the solution that worked for me.

1>Check to what you extend class: – In my case, I have tried my activity with extending AppCompatActivity class and the menu is showing proper and when I changed it to activity class then it stopped displaying.

Not Working: –
public class GridViewActivity extends Activity

2>Try to extend your class with AppCompatActivity class instead of activity class.

Working: –

public class GridViewActivity extends AppCompatActivity

Respondent: Neel Patel

Solution #7:

Call setHasOptionsMenu(true) from onCreate.

    public void onCreate(@Nullable Bundle savedInstanceState) {
Respondent: Artinium

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy