android - 什么时候应该在 FragmentTransaction 上调用 setReorderingAllowed()?

标签 android android-fragments fragmenttransaction

this part在 Google I/O 2017 的演讲中,演讲者介绍了一个新的 setReorderingAllowed() API,可以在 FragmentTransaction 上调用。

演讲者解释:

It allows all the execution to happen all at once without changing your fragment state and then at the very end we bring up all the fragments that need to be brought up and tear down all the fragments that need to be torn down…so we can optimize this for you.

并显示以下代码示例:

fragmentManager.beginTransaction()
    .replace(R.id.container, fragment1)
    .addToBackStack("state1")
    .setReorderingAllowed(true)
    .commit();

fragmentManager.beginTransaction()
    .replace(R.id.container, fragment2)
    .addToBackStack("state2")
    .setReorderingAllowed(true)
    .commit();

单独提交 FragmentTransaction 不会否定 .setReorderingAllowed(true) 为您提供的任何优化,因为它们是单独发生的吗?

由于这是一个新发布的 API,目前似乎没有可用的文档。

最佳答案

我相信他们提到的方法自支持库 25.1.0 以来就已经存在,但目前称为 setAllowOptimization(true)documentation明确指出“优化事务内和跨事务的操作”,因此它将优化不同的事务。

关于android - 什么时候应该在 FragmentTransaction 上调用 setReorderingAllowed()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44166085/

相关文章:

android - 在每个 viewpager fragment 中添加回调监听器

android - fragment 中的 onActivityResult 未称为 childFragment

android - 在使用 addToBackStack 的 Fragment 事务后单击后退按钮不执行任何操作

android - Android 中 FragmentTransaction 的类型不匹配与 getFragmentManager().beginTransaction()

android - 计算android中蓝牙设备之间的距离

android - TIME_TICK 会在深度 sleep 中广播吗?

android - 嵌套 ScrollView 布局下回收器 View 的 Scrolltoposition/smoothscrolltoposition

java - 抽屉导航应用程序在单击时不会更改 fragment

php - 如何在 PHP 和 MySql 中保存和管理 session ID 和用户 ID

android - 如何重用一个 fragment