FragmentFactory

public class FragmentFactory
extends Object

java.lang.Object
   ↳ androidx.fragment.app.FragmentFactory


Interface used to control the instantiation of Fragment instances. Implementations can be registered with a FragmentManager via FragmentManager.setFragmentFactory(FragmentFactory).

Summary

Public constructors

FragmentFactory()

Public methods

Fragment instantiate(ClassLoader classLoader, String className, Bundle args)

Create a new instance of a Fragment with the given class name.

static Class<? extends Fragment> loadFragmentClass(ClassLoader classLoader, String className)

Parse a Fragment Class from the given class name.

Inherited methods

Public constructors

FragmentFactory

public FragmentFactory ()

Public methods

instantiate

public Fragment instantiate (ClassLoader classLoader, 
                String className, 
                Bundle args)

Create a new instance of a Fragment with the given class name. This uses loadFragmentClass(ClassLoader, String) and the empty constructor of the resulting Class by default.

Note that this method is not responsible for calling Fragment.setArguments(Bundle) on the returned Fragment instance.

Parameters
classLoader ClassLoader: The default classloader to use for instantiation

className String: The class name of the fragment to instantiate.

args Bundle: The Fragment's arguments, if any. This will be null when inflating the Fragment from XML.

Returns
Fragment Returns a new fragment instance.

Throws
InstantiationException If there is a failure in instantiating the given fragment class. This is a runtime exception; it is not normally expected to happen.

loadFragmentClass

public static Class<? extends Fragment> loadFragmentClass (ClassLoader classLoader, 
                String className)

Parse a Fragment Class from the given class name. The resulting Class is kept in a global cache, bypassing the ClassLoader.loadClass(String) calls when passed the same class name again.

Parameters
classLoader ClassLoader: The default classloader to use for loading the Class

className String: The class name of the fragment to parse.

Returns
Class<? extends Fragment> Returns the parsed Fragment Class

Throws
Fragment.InstantiationException If there is a failure in parsing the given fragment class. This is a runtime exception; it is not normally expected to happen.