In a Fragment\'s Lifecycle, the onAttach() method is called before the onCreate() method. I can\'t wrap my head around this. Why would you attach a Fragment first?
Two Points from Android developer Site hints at why onAttach()
is called before onCreate()
in case of Fragment Life cycle.
So Fragment must FIRST "attach" itself to activity to defines its own view layout
onCreate
is Called to do initial creation of a fragment. It is obvious that you will create something only when its pre-condition of creation is in place (and the pre-condition is A fragment must always be embedded in an activity, and it must be attached to its Activity)