What are the differences between
onCreate() method in a
Fragment is called after the
onAttachFragment() but before that
In this method, you can assign variables, get
Intent extras, and anything else that doesn't involve the View hierarchy (i.e. non-graphical initialisations). This is because this method can be called when the
onCreate() is not finished, and so trying to access the View hierarchy here may result in a crash.
onCreate() is called (in the
onCreateView() is called. You can assign your
View variables and do any graphical initialisations. You are expected to return a
View from this method, and this is the main UI view, but if your
Fragment does not use any layouts or graphics, you can return
null (happens by default if you don't override).
As the name states, this is called after the
onCreate() has completed. It is called after
onCreateView(), and is mainly used for final initialisations (for example, modifying UI elements).
To sum up...
... they are all called in the
Fragment but are called at different times.
onCreate() is called first, for doing any non-graphical initialisations. Next, you can assign and declare any
View variables you want to use in
onCreateView(). Afterwards, use
onActivityCreated() to do any final initialisations you want to do once everything has completed.
_There are also some slightly different, but less developed questions/answers here on Stack Overflow: