在 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/