ListFragment和onActivityCreated调用了两次 [英] ListFragment and onActivityCreated called twice

查看:81
本文介绍了ListFragment和onActivityCreated调用了两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个listFragment,这是我的onActivityCreated:

i have a listFragment this is my onActivityCreated:

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    if (savedInstanceState != null) {
        utenti=savedInstanceState.getParcelableArrayList("array");
    }else{
        threadutenti= (GetUtenti) new GetUtenti(this.getActivity(), utenti).execute();
    }

当我旋转设备时,我的第一个saveInstanceState不为null(我知道了),但是在onActivityCreated之后调用了onActivityCreated null!为什么?我想在ListFragment而不是我的活动上获取对象utenti.

When i rotate my device i have first savedInstanceState non null (i got it) but after onActivityCreated is called with onActivityCreated null!! why? i want get my object utenti on ListFragment and not on my activity..

推荐答案

如果您总是在 Activity#onCreate() 中创建新片段,则可能会发生这种情况回调.
如果是真的,请检查此答案.您的 Fragment#onActivityCreated 将被调用两次:

This can happen if you're always creating a new fragment in your Activity#onCreate() callback.
If it's true, check this answer. Your Fragment#onActivityCreated will be called twice:

  • 第一次是由 FragmentActivity#onStart 调用 mFragments.dispatchActivityCreated() 触发的.它将通过保存的实例.
  • FragmentActivity#onStart 调用 mFragments.execPendingActions() 触发的第二时间.这次没有保存实例(因为正在响应添加新的Fragment而被调用).

这篇关于ListFragment和onActivityCreated调用了两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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