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

When should setReorderingAllowed() be called on a 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 明确指出 "optimizing operations within and across transactions" 因此它将优化不同的事务。