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