FragmentActivity 存在什么回调,即。 onAllFragmentsHaveBeenCreated()?

What callback exists for a FragmentActivity, ie. onAllFragmentsHaveBeenCreated()?

我正在尝试为我的 FragmentActivity 找到回调 'after' 所有片段都调用了 'onCreateView'。

原因是我的 Fragment 实现了我的接口:

public interface LifeCycleFragment {
    public void onResumeFragment();
}

当我从 MyActivity 调用片段时:

class MyActivity extends Activity
  onCreate() 
    fragment.onResumeFragment()

getActivity() 最终为空:

class MyFragment extends Fragment implements LifeCycleFragment

@Override
public void onResumeFragment() {
    Log.e(TAG, "- ON RESUME -");

    FragmentActivity activity = getActivity();
    // *****ACTIVITY IS NULL HERE AND THAT'S A PROBLEM ***//

我不确定如何解决这个问题,如有任何帮助,我们将不胜感激。

getActivity() 放在重写 onActivityCreated 方法中,并将其保存在 class 中用于 onResumeFragment()。我希望 Activity 在 onPause() 期间仍然保持不变。

您想要在 Fragment 和 Activity 之间进行通信的示例代码吗?我在 SO @ Passing data between fragments contained in an activity. The respective Google webpage is @ Communicating with Other Fragments.

中发布了一个答案

祝你好运,玩得开心...