8

At this part of a talk given at Google I/O 2017, the speaker introduces a new API for setReorderingAllowed() than can be called on a FragmentTransaction.

The speaker explains:

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.

And shows the following code sample:

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

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

Wouldn't committing the FragmentTransactions separately negate any optimization that .setReorderingAllowed(true) gives you because they are occurring separately?

Since this is a newly announced API it looks like there is no documentation currently available.

Dick Lucas
  • 12,289
  • 14
  • 49
  • 76
  • The method `setAllowOptimization` was deprecated in API level 26.0.0-beta2 and has been renamed to `setReorderingAllowed(boolean)`. [Documentation](https://developer.android.com/reference/android/support/v4/app/FragmentTransaction.html#setReorderingAllowed(boolean)) is also available now. – Wahib Ul Haq Jul 13 '17 at 15:57

1 Answers1

1

I believe the method they mention already exists since support library 25.1.0 but is currently called setAllowOptimization(true). The documentation clearly states "optimizing operations within and across transactions" so it will optimize distinct transactions.

BladeCoder
  • 12,779
  • 3
  • 59
  • 51
  • SEE ABOVE COMMENT: "The method setAllowOptimization was deprecated in API level 26.0.0-beta2 and has been renamed to setReorderingAllowed(boolean). Documentation is also available now." – radley Jun 14 '18 at 10:58
  • To be clear: I never said anyone should use `setAllowOptimization()`. I clearly stated it was the **old name** of the same method and referred to the documentation of it, which answers the question. – BladeCoder Jun 17 '18 at 17:02