Dagger2 and in one of the articles I found this class
public class App extends Application { private static AppComponent component; public static AppComponent getComponent() { return component; } @Override public void onCreate() { super.onCreate(); component = buildComponent(); } protected AppComponent buildComponent() { return DaggerAppComponent.builder() .anotherModule(new AnotherModule()) .modelModule(new ModelModule()) .build(); } } Which is convenient to use for initialization, but the fact is that the onCreate() method is not called and accordingly I get null when I call the App.getComponent().inject(this);
At first I took and just did this:
public class App extends Application { public static AppComponent getComponent() { return DaggerAppComponent.builder() .anotherModule(new AnotherModule()) .modelModule(new ModelModule()) .build(); } } But then I thought that if it was done that way, then why did it do that))
- But then why doesn't
onCreate()? - and the second question is why not to do it in my second example?