I found a really strange behavior in the Fragment
lifecycle.
After several tests on one Fragment
, I realized than I got this execution order every time:
I am really surprised because I was convinced that onStart
would only be called after the execution of onCreateOptionsMenu
.
FYI, I was trying to set a MenuItem
as a global class variable in onCreateOptionsMenu
to be able to use it in onStart
. Of course I got a null pointer because of the execution order explained above.
It seems the more I dig into the Fragment's lifecycle, the more I am lost and the documentation only details the main methods, never the ones such as onCreateOptionsMenu
, onPrepareOptionsMenu
, onCreateContextMenu
etc.
Does someone has any additional information about this, the documentation is not really helpful...
Thank you
Check this out https://github.com/xxv/android-lifecycle. There you can see a full lifecycle for both fragment and activity.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With