By Alvin Alexander. Last updated: August 3, 2017
Android FAQ: When is the Android Fragment onCreateOptionsMenu
method called?
I was just working through a problem with an Android Menu and MenuItem, and added some debug code to the methods in my Android Fragment, and found that the onCreateOptionsMenu
method is called after onStart
. I didn’t put Log/debug code in every activity lifecycle method, but for the ones I did add logging code to, the specific order of the fragment method calls looked like this:
- onCreate
- onCreateView
- onActivityCreated
- onStart
- onCreateOptionsMenu
I was surprised, I thought onCreateOptionsMenu
was called earlier — which led to my null pointer exceptions — but this is the way the calls worked with Android 7.x.
The Android method lifecycle image comes from this android.com page.