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:
  • 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.