File tree Expand file tree Collapse file tree
app/src/main/java/com/gregoriopalama/daggerexample Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package com .gregoriopalama .daggerexample ;
22
3+ import android .app .Activity ;
34import android .app .Application ;
45
6+ import com .gregoriopalama .daggerexample .di .DaggerAppComponent ;
7+
8+ import javax .inject .Inject ;
9+
10+ import dagger .android .AndroidInjector ;
11+ import dagger .android .DispatchingAndroidInjector ;
12+ import dagger .android .HasActivityInjector ;
13+
514/**
6- * This will be the application. For now, it will be empty
15+ * This is the application. It uses the generated DaggerAppComponent, and inject itself.
16+ * It also implements HasActivityInjector, in order to provide the possibility to inject
17+ * activities directly from inside of them.
718 *
819 * @author Gregorio Palamà
920 */
1021
11- public class DaggerExampleApplication extends Application {
22+ public class DaggerExampleApplication extends Application implements HasActivityInjector {
23+ @ Inject
24+ DispatchingAndroidInjector <Activity > dispatchingAndroidInjector ;
25+
26+ @ Override
27+ public void onCreate () {
28+ super .onCreate ();
29+
30+ DaggerAppComponent
31+ .builder ()
32+ .application (this )
33+ .build ()
34+ .inject (this );
35+ }
36+
37+ @ Override
38+ public AndroidInjector <Activity > activityInjector () {
39+ return dispatchingAndroidInjector ;
40+ }
1241}
You can’t perform that action at this time.
0 commit comments