Currently (Android API 17), the only mention of super
in the Android Reference on Fragment is casually via some code examples (unlike the Android Reference on Activity, which carefully notes where super
is required).
SO suggests searching the web as needed, or waiting for a crash, to identify where a call to super
is required. I'm asking SO users to share their knowledge on which of the Fragment lifecycle methods require a call to super
.
super
onAttach()
onCreate()
- presumably yes, as Activity
version requires itonCreateView()
- seems ok with or withoutonActivityCreated()
onViewStateRestored()
onStart()
- presumably yes, as Activity
version requires itonResume()
- presumably yes, as Activity
version requires it
onPause()
- presumably yes, as Activity
version requires it
onStop()
- presumably yes, as Activity
version requires itonDestroyView()
onDestroy()
- presumably yes, as Activity
version requires itonDetach()
onSaveInstanceState()
- presumably yes, as Activity
version requires it
onCreate(Bundle) called to do initial creation of the fragment. onCreateView(LayoutInflater, ViewGroup, Bundle) creates and returns the view hierarchy associated with the fragment.
onCreate() is called to do initial creation of the fragment. onCreateView() is called by Android once the Fragment should inflate a view. onViewCreated() is called after onCreateView() and ensures that the fragment's root view is non-null .
All of the corresponding Activity lifecycle methods except onSaveInstanceState
require calls to super. In addition:
onAttach()
- yesonActivityCreated()
- yesonViewStateRestored()
- is not a Fragment methodonDestroyView()
- yesonDetach()
- yes onSaveInstanceState()
- from Fragment#onSaveInstanceState it
looks like a noAll of the methods that require calls to super share the first line of their method in android.app.Fragment:
mCalled = true;
That way the FragmentManager can check if mCalled is true and throw a SuperNotCalledException when it is not called. See FragmentManager#moveToState to see this implementation.
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