Class AndroidInjection


  • @Beta
    public final class AndroidInjection
    extends java.lang.Object
    Injects core Android types.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void inject​(android.app.Activity activity)
      Injects activity if an associated AndroidInjector implementation can be found, otherwise throws an IllegalArgumentException.
      static void inject​(android.app.Fragment fragment)
      Injects fragment if an associated AndroidInjector implementation can be found, otherwise throws an IllegalArgumentException.
      static void inject​(android.app.Service service)
      Injects service if an associated AndroidInjector implementation can be found, otherwise throws an IllegalArgumentException.
      static void inject​(android.content.BroadcastReceiver broadcastReceiver, android.content.Context context)
      Injects broadcastReceiver if an associated AndroidInjector implementation can be found, otherwise throws an IllegalArgumentException.
      static void inject​(android.content.ContentProvider contentProvider)
      Injects contentProvider 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​(android.app.Activity activity)
        Injects activity if an associated AndroidInjector implementation can be found, otherwise throws an IllegalArgumentException.
        Throws:
        java.lang.RuntimeException - if the Application doesn't implement HasAndroidInjector.
      • inject

        public static void inject​(android.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.
      • inject

        public static void inject​(android.app.Service service)
        Injects service if an associated AndroidInjector implementation can be found, otherwise throws an IllegalArgumentException.
        Throws:
        java.lang.RuntimeException - if the Application doesn't implement HasAndroidInjector.
      • inject

        public static void inject​(android.content.BroadcastReceiver broadcastReceiver,
                                  android.content.Context context)
        Injects broadcastReceiver if an associated AndroidInjector implementation can be found, otherwise throws an IllegalArgumentException.
        Throws:
        java.lang.RuntimeException - if the Application from Context.getApplicationContext() doesn't implement HasAndroidInjector.
      • inject

        public static void inject​(android.content.ContentProvider contentProvider)
        Injects contentProvider if an associated AndroidInjector implementation can be found, otherwise throws an IllegalArgumentException.
        Throws:
        java.lang.RuntimeException - if the Application doesn't implement HasAndroidInjector.