Package icyllis.modernui.fragment

# Class FragmentFactory

java.lang.Object
icyllis.modernui.fragment.FragmentFactory

@Experimental public class FragmentFactory extends Object
Interface used to control the instantiation of `Fragment` instances. Implementations can be registered with a `FragmentManager` via `FragmentManager.setFragmentFactory(FragmentFactory)`.

See Also:
  - `FragmentManager.setFragmentFactory(FragmentFactory)`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `FragmentFactory()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Fragment`
  `instantiate(Class<? extends Fragment> clazz)`
  Create a new instance of a Fragment with the given class name.
  `Fragment`
  `instantiate(ClassLoader classLoader, String className)`
  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.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### FragmentFactory

    public FragmentFactory()

- ## Method Details

  - ### loadFragmentClass

    @Nonnull public static Class<? extends 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 `Class.forName(String)` calls when passed the same class name again.
    Parameters:
      `classLoader` - The classloader to use for loading the Class
      `className` - The class name of the fragment to parse.
    Returns:
      Returns the parsed Fragment Class
    Throws:
      `RuntimeException` - If there is a failure in parsing the given fragment class. This is a runtime exception; it is not normally expected to happen.

  - ### instantiate

    @Nonnull public Fragment instantiate(@Nonnull ClassLoader classLoader, @Nonnull String className)
    Create a new instance of a Fragment with the given class name. This uses `loadFragmentClass(ClassLoader, String)` and then `instantiate(Class)`.
    Parameters:
      `classLoader` - The classloader to use for instantiation
      `className` - The class name of the fragment to instantiate.
    Returns:
      Returns a new fragment instance.
    Throws:
      `RuntimeException` - If there is a failure in instantiating the given fragment class. This is a runtime exception; it is not normally expected to happen.

  - ### instantiate

    @Nonnull public Fragment instantiate(@Nonnull Class<? extends Fragment> clazz)
    Create a new instance of a Fragment with the given class name. This the empty constructor of the resulting Class by default.
    Parameters:
      `clazz` - The loaded class of the fragment to instantiate.
    Returns:
      Returns a new fragment instance.
    Throws:
      `RuntimeException` - If there is a failure in instantiating the given fragment class. This is a runtime exception; it is not normally expected to happen.