Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onCreateOptionsMenu is not called

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?

like image 728
vetalitet Avatar asked Aug 16 '13 09:08

vetalitet


3 Answers

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);
}
like image 136
Golan Shay Avatar answered Oct 03 '22 17:10

Golan Shay


there is concept called ActionBar from API 11, so option menu is not use for tablet version.

check for ActionBar tutorial.. see below link

http://developer.android.com/guide/topics/ui/actionbar.html

like image 24
AndroUser Avatar answered Oct 03 '22 17:10

AndroUser


If your activity is extending from Activity class try changing it to AppCompatActivity..

like image 27
Sathyajith Avatar answered Oct 01 '22 17:10

Sathyajith