This question already has an answer here:
- Why is onAttach called before onCreate? 4 answers
Exactly when is onAttach
called during the Fragment-Activity lifecycles?
I am aware of the Fragment Life-Cycle but exactly when?
Is it when the fragment object is initiated or when fragment manager is called?
onAttach is called after Fragment is associated with its Activity.
In activity the first method is onCreate. onCreate of activity add the fragment and in this moment onAttach is called. like in the picture![enter image description here](https://i.stack.imgur.com/fRxIQ.png)
Ref: http://baiduhix.blogspot.com.br/2015/08/android-how-to-do-findviewbyid-in.html
EDIT:
updated lifecycle of Android
Ref: https://github.com/xxv/android-lifecycle