onCreate, onCreateOptionsMenu, onResume, what is the order of execution?
Asked Answered
P

1

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?

Photographic answered 23/9, 2013 at 9:1 Comment(1)
Check this SOBefore
M
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).

Mothering answered 23/9, 2013 at 9:9 Comment(2)
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...Photographic
Maybe inflate for new orientation.Mothering

© 2022 - 2024 — McMap. All rights reserved.