Does the new FragmentFactory make the use of Fragment Arguments redundant?

In the book in chapter 12, it is discussed in the first “For the more curious” section of the reasoning behind fragment arguments.

There was a newly released API called FragmentFactory by Google. It seems that we can create fragments using this factory with arguments. Just wanted to confirm my understanding is correct.

Does this mean we don’t need to use the newInstance pattern if we use this??

1 Like

If you’ve already been using the Navigation AC with SafeArgs, then you would also move away from the newInstance() pattern. The Navigation AC still uses arguments that you would retrieve inside of onCreate().

However, the article you linked seems to move away from arguments all together by placing the arguments in to an initial state bundled. This seems like a nice feature since if we are saving state across configuration changes we’d be using the bundle, so now in the initial fragment creation it appears that we are coming back from a configuration change and can handle both scenarios the same.

It will be interesting to see if the Navigation AC replaces the SafeArgs with the FragmentFactory. Either way, while newInstance() is nice for encapsulation - once we give up control of our Fragment creation we need to allow for other constructors to be able to be called.