7

I'm sorry if this question was asked before... Well anyway as what the title asked, when does onCreateOptionsMenu executed? before or after onResume?

In my app, when the activity first run/opened the order will be onCreate --> onResume --> onCreateOptionsMenu

But if I change the orientation of the device, it'll automatically called onDestroy and thus the activity will be re-created, in this case the order will be onCreate --> onCreateOptionsMenu --> onResume

I'm so confused now... anybody can give an explanation on this?

CodingBird
  • 705
  • 2
  • 11
  • 22
  • Check this [SO](http://stackoverflow.com/questions/7705927/android-when-is-oncreateoptionsmenu-called-during-activity-lifecycle) – Srikanth Roopa Sep 23 '13 at 09:22

1 Answers1

7

You can read about onCreateOptionsMenu this :

This is only called once, the first time the options menu is displayed. To update the menu every time it is displayed, see onPrepareOptionsMenu(Menu).

Leri
  • 12,367
  • 7
  • 43
  • 60
getKonstantin
  • 1,220
  • 9
  • 14
  • 1
    thanks for the info! I've settled it with invalidateOptionsMenu() which will call onPrepareOptionsMenu(Menu).. But still, onCreateOptionsMenu will be called everytime, the activity is destroyed and created again. So everytime I rotate my device, onCreateOptionsMenu() will be executed. and the order of execution is different from if I open the activity for the very first time. This behavior confuses me... – CodingBird Sep 23 '13 at 09:47
  • Maybe inflate for new orientation. – getKonstantin Sep 23 '13 at 10:18