Class AndroidSupportInjection


  • @Beta
    public final class AndroidSupportInjection
    extends java.lang.Object
    Injects core Android types from support libraries.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void inject​(androidx.fragment.app.Fragment fragment)
      Injects fragment if an associated AndroidInjector implementation can be found, otherwise throws an IllegalArgumentException.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • inject

        public static void inject​(androidx.fragment.app.Fragment fragment)
        Injects fragment if an associated AndroidInjector implementation can be found, otherwise throws an IllegalArgumentException.

        Uses the following algorithm to find the appropriate AndroidInjector<Fragment> to use to inject fragment:

        1. Walks the parent-fragment hierarchy to find the a fragment that implements HasAndroidInjector, and if none do
        2. Uses the fragment's activity if it implements HasAndroidInjector, and if not
        3. Uses the Application if it implements HasAndroidInjector.
        If none of them implement HasAndroidInjector, a IllegalArgumentException is thrown.
        Throws:
        java.lang.IllegalArgumentException - if no parent fragment, activity, or application implements HasAndroidInjector.