问题描述
我的活动等待一个异步操作,当它从异步操作中回听后,它需要将信息传递给它内部的两个片段。
要求
1.这两个片段都需要它们的 onCreateView
调用完成它们的布局加载,
2.它们需要自己附加到它们的活动,这样 getActivity()
才能工作。
我在这两个片段中都写了一个 setData()
方法,并且正在寻找活动生命周期中的正确位置来调用它们。
活动的onCreate()
不起作用, onStart()活动的code>不起作用,片段的
onStart()
不起作用。
没有什么可行的,我在这里错过了什么? 的官方文档清楚地解释了这一点 - 请参阅如果有些事情不清楚,那就问后续问题。
SituationMy activity waits on an Async operation and after it hears back from async operation, it needs to pass information to 2 fragments inside it.
Requirement1. Both fragments need their onCreateView
calls to be done for them to have their layouts loaded,2. They need for themselves to be attached to their activity so that getActivity()
works.
I wrote a setData()
method in both the fragments and am looking for the "correct" place in the activity's lifecycle to invoke them.
onCreate()
of the activity does not work, onStart()
of the activity does not work and onStart()
of the fragment does not work.
Nothing works, what am I missing here?
The official documentation for the Fragment lifecycle explains this clearly - please refer to it and then ask follow-up questions if something is unclear.
这篇关于片段生命周期就其活动而言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!