{% setvar book_path %}/reference/kotlin/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

FragmentFactory

{% setvar page_path %}androidx/fragment/app/FragmentFactory.html{% endsetvar %} {% setvar can_switch %}1{% endsetvar %} {% include "reference/_kotlin_switcher2.md" %}

class FragmentFactory


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

See also
setFragmentFactory

androidx.fragment.app.FragmentManager#setFragmentFactory(FragmentFactory)

Summary

Public constructors

Public functions

Fragment
instantiate(classLoader: ClassLoader, className: String)

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

Class<Fragment>
loadFragmentClass(classLoader: ClassLoader, className: String)

Parse a Fragment Class from the given class name.

Public constructors

FragmentFactory

FragmentFactory()

Public functions

instantiate

fun instantiate(classLoader: ClassLoader, className: String): Fragment

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

Parameters
classLoader: ClassLoader

The default classloader to use for instantiation

className: String

The class name of the fragment to instantiate.

Returns
Fragment

Returns a new fragment instance.

Throws
androidx.fragment.app.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

fun loadFragmentClass(classLoader: ClassLoader, className: String): Class<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: String

The class name of the fragment to parse.

Returns
Class<Fragment>

Returns the parsed Fragment Class

Throws
androidx.fragment.app.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.