How to open the options menu programmatically?

Or just call Activity.openOptionsMenu()?


Apparently, doing it in onCreate breaks app, since Activity's not yet attached to a window. If you do it like so:

@Override
public void onAttachedToWindow() {
    openOptionsMenu(); 
};

...it works.


For developers using the new Toolbar class of the Support Library, this is how it's done:

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.showOverflowMenu();