Last active
March 20, 2019 04:20
-
-
Save namphho/ea68f0d48614136b96de888e8d426096 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Injects core Android types. */ | |
@Beta | |
public final class AndroidInjection { | |
private static final String TAG = "dagger.android"; | |
/** | |
* Injects {@code activity} if an associated {@link AndroidInjector} implementation can be found, | |
* otherwise throws an {@link IllegalArgumentException}. | |
* | |
* @throws RuntimeException if the {@link Application} doesn't implement {@link | |
* HasActivityInjector}. | |
*/ | |
public static void inject(Activity activity) { | |
checkNotNull(activity, "activity"); | |
Application application = activity.getApplication(); | |
if (!(application instanceof HasActivityInjector)) { | |
throw new RuntimeException( | |
String.format( | |
"%s does not implement %s", | |
application.getClass().getCanonicalName(), | |
HasActivityInjector.class.getCanonicalName())); | |
} | |
AndroidInjector<Activity> activityInjector = | |
((HasActivityInjector) application).activityInjector(); | |
checkNotNull(activityInjector, "%s.activityInjector() returned null", application.getClass()); | |
activityInjector.inject(activity); | |
} | |
.... | |
private AndroidInjection() {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment