7

Is onCreateOptionsMenu() of action bar called before or after the onStart() of activity?

mthandr
  • 3,062
  • 2
  • 23
  • 33

3 Answers3

8

onStart() is called first. (I tried putting log messages in the methods).

enter image description here

ElectronicGeek
  • 3,312
  • 2
  • 23
  • 35
4

I found this order to be the correct one

onCreate() - onStart() - onResume()- onCreateOptionsMenu()

CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
  • 2
    I believe it's quite mind and app-breaking. I though in onStart I can access everything already. And looks like originally onCreateOptionsMenu was called somewhere during or after onCreate – norekhov May 24 '19 at 13:28
-2

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

This is written in the Android documentation.

  • onPrepareOptionsMenu is not called every time menu is to be displayed anymore. onInvalidateOptionsMenu() is required to call onCreateOptionsMenu() and onPrepareOptionsMenu() Jelly Bean onwards (except the first time ofcourse). This also makes me think onPrepareOptionsMenu() is pretty much useless, unless someone can give an example of a use-case to me. – Dhruva Bharadwaj Mar 13 '14 at 17:39