问题描述
我在哪里我的片段的 onActivityCreated()
方法被调用后,我的活动的 ONSTART()
方法被调用。这似乎意味着,我的活动的的onCreate()
方法之后 ONSTART整理()
?这可能不会是这样......可以吗?当我的活动的生命周期就是我的碎片的 onActivityCreated()
叫什么名字?此外,如果我有多个片段,我怎么能控制片段 onActivityCreated()
电话?
在我的活动:
@覆盖
保护无效的OnStart(){
super.onStart();
的methodA(); //这就是所谓的...
}
在我的片段:
@覆盖
公共无效onActivityCreated(包savedInstanceState){
super.onActivityCreated(savedInstanceState);
的methodB(); // ... 在这之前
}
记住onActivityCreated()方法只是一个回调从活动片段。
错!活动和碎片是分开的,在活动和onActivityCreated所以onCreated()()的方法在片段的方法可能是不一样的。如上所述,在片段,它只是与活动状态的回调映射。
让我们来看看这张图有一个更好的了解。
在从谷歌官方文件:活动ONSTART()
片段回调:onActivityCreated()
最后一个:
这取决于哪种方式,你用你的片段添加到活动。基本上,订货会的补充片段的顺序。
I'm having an issue where my fragment's onActivityCreated()
method is being called after my activity's onStart()
method is called. This seems to imply that my activity's onCreate()
method is finishing after onStart()
? That can't be the case ... Can it? When in my activity's lifecycle is my fragment's onActivityCreated()
called? Furthermore, if I have multiple fragments, how can I control the order of the fragments' onActivityCreated()
calls?
In my activity:
@Override
protected void onStart() {
super.onStart();
methodA(); // this is called ...
}
In my fragment:
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
methodB(); // ... before this
}
Remember that onActivityCreated() method just a callback for the fragment from activity.
Wrong! Activity and fragment is separate, So onCreated() method in Activity and onActivityCreated() method in fragment could not be the same. As above, in Fragment it's just a callback mapping with activity state.
Let's have a look at this picture to have a better understanding.
In Official document from Google:Activity onStart()
Fragment callback: onActivityCreated()
The last one:
It's depend on which way you use to add your fragments to activity. Basically the order will be the order of added fragments.
这篇关于活动ONSTART()片段的onActivityCreated之前被称为()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!