I don't know when to use onCreate()
or onCreateView()
.
I have used onCreate()
and onCreateView()
lifecycle methods.
I think onCreate()
for Activity and onCreateView()
for Fragment. But I am not sure. Can I use onCreate()
LifeCycle method in Fragment? I hope somebody can help me!
onCreate is called on initial creation of the fragment. You do your non graphical initializations here. It finishes even before the layout is inflated and the fragment is visible.
onCreateView is called to inflate the layout of the fragment i.e graphical initialization usually takes place here. It is always called sometimes after the onCreate method.
Activity lifecycle explained - http://developer.android.com/reference/android/app/Activity.html
Fragment lifecycle explained - http://developer.android.com/guide/components/fragments.html#Creating
Detailed lifecycle diagram - https://github.com/xxv/android-lifecycle
From documents :
Link to documentation of
onCreate
Link to documentation of
onCreateView