FragmentFactory
public class FragmentFactory
Interface used to control the instantiation of Fragment instances. Implementations can be registered with a FragmentManager via setFragmentFactory.
| See also | |
|---|---|
setFragmentFactory |
Summary
Public constructors |
|---|
Public methods |
|
|---|---|
@NonNull Fragment |
instantiate(@NonNull ClassLoader classLoader, @NonNull String className)Create a new instance of a Fragment with the given class name. |
static @NonNull Class<Fragment> |
loadFragmentClass(Parse a Fragment Class from the given class name. |
Public constructors
Public methods
instantiate
public @NonNull Fragment instantiate(@NonNull ClassLoader classLoader, @NonNull String className)
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 | |
|---|---|
@NonNull ClassLoader classLoader |
The default classloader to use for instantiation |
@NonNull String className |
The class name of the fragment to instantiate. |
| 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
public static @NonNull Class<Fragment> loadFragmentClass(
@NonNull ClassLoader classLoader,
@NonNull String className
)
Parse a Fragment Class from the given class name. The resulting Class is kept in a global cache, bypassing the forName calls when passed the same class name again.
| Parameters | |
|---|---|
@NonNull ClassLoader classLoader |
The default classloader to use for loading the Class |
@NonNull String className |
The class name of the fragment to parse. |
| 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. |