onCreateOptionsMenu is not called

vetalitet picture vetalitet · Aug 16, 2013 · Viewed 12.8k times · Source

I have simple application.

Here is MyActivity.java

public class MyActivity extends Activity {
    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        return super.onCreateOptionsMenu(menu);
    }
}

And I don't really understand why method onCreateOptionsMenu is called on phone and is not called on tablet?

Answer

Golan Shay picture Golan Shay · Jun 2, 2015

If you're using ToolBar:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_map);
    mToolbar = (Toolbar) findViewById(R.id.tool_bar);
    setSupportActionBar(mToolbar);
}