- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
更重要的是,在 onCreate/onCreateView 中,我已经调用 FragmentManager.findFragmentByTag() 来查找我的 fragment 的任何现有实例,它似乎找到了它。
那么putFragment/getFragment有什么意义呢?它会节省一些额外的东西还是会导致其他生命周期的事情发生?它只是做或多或少相同事情的 findFragmentByTag() 的替代方法吗?因为在我看来, fragment 会自动为我保存,而无需使用 FragmentManager.putFragment()。
最佳答案
So what is the point of putFragment/getFragment?
根据目前的实现,什么putFragment(Bundle bundle, String key, Fragment fragment)
do 是将 fragment 的索引放入带有参数键的包中。然后getFragment(Bundle bundle, String key)
获取同一索引处的 fragment ,可以使用相同的键从 bundle 中检索该 fragment 。 Fragment 只有在添加到 FragmentManager 后才会在 FragmentManager 中有其索引,因此只有在添加后才能在 Fragment 上调用 putFragment()。
Does it save something extra or cause additional lifecycle stuff to happen?
它只保存一个 fragment 的索引,没有其他东西,也不会导致任何额外的生命周期东西。
Is it just an alternative to findFragmentByTag() that does more or less the same thing?
是的,我认为是。
按照目前的实现,putFragment/getFragment的作用可以用findFragmentByTag()
来实现也。但是 putFragment/getFragment 的功能非常有限,因为你不能在没有 bundle 参数的情况下使用它们,这意味着你必须调用 putFragment()
在onSaveInstanceState()
.
关于android - FragmentManager.put/getFragment 与 findFragmentByTag,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27240756/
我正在使用 viewpager 并编译 API 23。我在我的代码中显示以下语句的编译错误,但该项目确实可以编译。 List fragments = getSupportFragmentManager
我正在使用支持库 v4,但未能保存 fragment 的状态。 @Override protected void onSaveInstanceState(Bundle outState) {
调用 getSupportFragmentManager().getFragments() 显示编译时错误,并显示以下消息: getSupportFragmentManager().getFragme
在我有的 XML 我想从 View 中获取 fragment 。 documentation建议使用 FragmentContainerView fcv = findViewById(R.id.id
我有一个托 pipe fragment 的父 fragment 。我对我的应用程序进行了压力测试,通过在开发人员选项中选中“不保留 Activity ”,然后按下主页按钮来强制终止它。 可以看到父 f
我正在开发 Android 3.1 平板电脑应用程序。 我在一项 Activity 中使用 ViewPager 和 fragment 。我的问题是我不知道如何为 fragment 设置 ID 或标签。
更重要的是,在 onCreate/onCreateView 中,我已经调用 FragmentManager.findFragmentByTag() 来查找我的 fragment 的任何现有实例,它似乎
我有一个使用 fragment 的应用程序,我正在研究如何在具有双 Pane 的 Activity 和作为独立的 Activity 中使用相同的 fragment 。仍然不确定完成此操作的最佳方法,但
URL.getRef() 和 URI.getFragment() 是一样的吗? 如果不是,它们有何不同? 运行下面的测试时,结果是一样的: String url = "http://c.b.a.com
从 SDK 26.0.0-beta1 及更高版本开始,使用 getFragments https://developer.android.com/reference/android/support/v
getFragments 方法在最新版本的支持库中被注释为@RestrictTo(LIBRARY_GROUP),这意味着它不供外部使用。 version history 中没有此更改的记录但对于早期版
编辑 2 我现在设法摆脱了使用这里的技巧 https://code.google.com/p/android/issues/detail?id=42601#c10 的错误所以这就是为什么我最后一次编辑
我有 TabLayout,其中使用 FragmentPagerAdapter 通过 ViewPager 创建了 3 个选项卡和 3 个 fragment 。滑动到第三个选项卡,中断第一个选项卡的一位并
我是一名优秀的程序员,十分优秀!