Skip to content

Instantly share code, notes, and snippets.

@mitchtabian
Last active April 5, 2019 20:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mitchtabian/de403c0611b0961f30c801705ebce83c to your computer and use it in GitHub Desktop.
Save mitchtabian/de403c0611b0961f30c801705ebce83c to your computer and use it in GitHub Desktop.
Example of NOT making use of @Component.Builder and @BindsInstance (this is the old way)
@Singleton
@Component(
modules = {
AndroidInjectionModule.class,
AppModule.class,
ActivityBuildersModule.class
})
public interface AppComponent extends AndroidInjector<BaseApplication> {
}
public void init(BaseApplication app){
appComponent = DaggerAppComponent.builder().appModule(new AppModule(app)).build();
appComponent.inject(app);
}
@Module
public class AppModule {
Application application;
public AppModule(Application application) {
this.application = application;
}
@Provides
Application provideApplicationContext(){
return application;
}
@Singleton
@Provides
Drawable getDrawable(Application application){ // application is available here
return ContextCompat.getDrawable(application, R.drawable.ic_launcher_background);
}
}
@Inject
Drawable getDrawable;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(getDrawable == null){
Log.d(TAG, "onCreate: drawable is null.");
}
else {
Log.d(TAG, "onCreate: drawable is NOT null.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment