When is onAttach called during the Fragment LifeCy

2019-01-12 18:20发布

This question already has an answer here:

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?

2条回答
Lonely孤独者°
2楼-- · 2019-01-12 18:49
叛逆
3楼-- · 2019-01-12 19:05

In activity the first method is onCreate. onCreate of activity add the fragment and in this moment onAttach is called. like in the pictureenter image description here

Ref: http://baiduhix.blogspot.com.br/2015/08/android-how-to-do-findviewbyid-in.html

EDIT:

updated lifecycle of Android

enter image description here

Ref: https://github.com/xxv/android-lifecycle

查看更多
登录 后发表回答