gpt4 book ai didi

android - getActivity().getFragmentManager() 与 fragment.getFragmentManager()

转载 作者:行者123 更新时间:2023-11-29 01:07:06 30 4
gpt4 key购买 nike

我真的把这两种组合搞混了

getActivity().getFragmentManager()

fragment.getFragmentManager()

好像我们看到了 Activity.java 的内部实现

public FragmentManager getFragmentManager() {
return mFragments.getFragmentManager();
}

而 Fragment.java 有

 final public FragmentManager getFragmentManager() {
return mFragmentManager;
}

这是否意味着我们总是有不同的 FragmentManager 或其他?

最佳答案

fragment 是可以放置在 Activity 中的应用程序用户界面或行为的一部分。与 fragment 的交互是通过 FragmentManager 完成的,可以通过 Activity.getFragmentManager() 获得。 Fragment.getFragmentManager() .

getActivity().getFragmentManager()

Return the FragmentManager for interacting with fragments associated with this activity.

fragment.getFragmentManager()

Return the FragmentManager for interacting with fragments associated with this fragment's activity. Note that this will be non-null slightly before getActivity(), during the time from when the fragment is placed in a FragmentTransaction until it is committed and attached to its activity.

If this Fragment is a child of another Fragment, the FragmentManager returned here will be the parent's getChildFragmentManager().

关于android - getActivity().getFragmentManager() 与 fragment.getFragmentManager(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46089079/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com