在 Fragment LifeCycle 期间什么时候调用 onAttach? [英] When is onAttach called during the Fragment LifeCycle?

查看:45
本文介绍了在 Fragment LifeCycle 期间什么时候调用 onAttach?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Exactly when is onAttach called during the Fragment-Activity lifecycles?

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

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?

推荐答案

在活动中,第一个方法是 onCreate.活动的 onCreate 添加片段,此时 onAttach 被调用.如图所示

In activity the first method is onCreate. onCreate of activity add the fragment and in this moment onAttach is called. like in the picture

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

这篇关于在 Fragment LifeCycle 期间什么时候调用 onAttach?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆