The Android Developer Challenge is back! Submit your idea before December 2.

FragmentFactory

open class FragmentFactory
kotlin.Any
   ↳ 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

Interface used to control the instantiation of Fragment instances.

Public methods

open Fragment
instantiate(@NonNull classLoader: ClassLoader, @NonNull className: String)

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

open static Class<out Fragment!>
loadFragmentClass(@NonNull classLoader: ClassLoader, @NonNull className: String)

Parse a Fragment Class from the given class name.

Public constructors

<init>

FragmentFactory()

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

Public methods

instantiate

@NonNull open fun instantiate(@NonNull classLoader: ClassLoader, @NonNull className: String): Fragment

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.

Parameters
classLoader ClassLoader: The default classloader to use for instantiation
className ClassLoader: The class name of the fragment to instantiate.
Return
Fragment: Returns a new fragment instance.
Exceptions
Fragment.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

@NonNull open static fun loadFragmentClass(@NonNull classLoader: ClassLoader, @NonNull className: String): Class<out Fragment!>

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

Parameters
classLoader ClassLoader: The default classloader to use for loading the Class
className ClassLoader: The class name of the fragment to parse.
Return
Class<out Fragment!>: Returns the parsed Fragment Class
Exceptions
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.