Home » Android » android – onCreate, onCreateOptionsMenu, onResume, what is the order of execution?

android – onCreate, onCreateOptionsMenu, onResume, what is the order of execution?

Posted by: admin June 16, 2020 Leave a comment

Questions:

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?

How to&Answers:

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).