Java 在 Fragment LifeCycle 期间什么时候调用 onAttach?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36339811/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 17:44:11  来源:igfitidea点击:

When is onAttach called during the Fragment LifeCycle?

javaandroidandroid-fragments

提问by Ackman

Exactly when is onAttachcalled during the Fragment-Activity lifecycles?

onAttach在 Fragment-Activity 生命周期中究竟何时被调用?

I am aware of the Fragment Life-Cycle but exactly when?

我知道 Fragment Life-Cycle 但具体是什么时候?

Is it when the fragment object is initiated or when fragment manager is called?

是在启动片段对象时还是在调用片段管理器时?

采纳答案by Lucas Ferraz

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

在活动中,第一个方法是 onCreate。活动的 onCreate 添加片段,此时 onAttach 被调用。就像图片中一样在此处输入图片说明

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

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

EDIT:

编辑:

updated lifecycle of Android

更新的 Android 生命周期

enter image description here

在此处输入图片说明

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

参考:https: //github.com/xxv/android-lifecycle

回答by Wilder Pereira