0

I'm learning android architecture pattern specifically MVVM, I see examples of it. often I see people use dependency injection and almost the code has class that extended from Application class I want to understand its purpose and want to know the using of dependency injection.

Example of the class:

public class MvvmApp extends Application implements HasActivityInjector {

@Inject
DispatchingAndroidInjector<Activity> activityDispatchingAndroidInjector;

@Inject
CalligraphyConfig mCalligraphyConfig;

@Override
public DispatchingAndroidInjector<Activity> activityInjector() {
    return activityDispatchingAndroidInjector;
}

@Override
public void onCreate() {
    super.onCreate();

    DaggerAppComponent.builder()
            .application(this)
            .build()
            .inject(this);

    AppLogger.init();

    AndroidNetworking.initialize(getApplicationContext());
    if (BuildConfig.DEBUG) {
        AndroidNetworking.enableLogging(HttpLoggingInterceptor.Level.BODY);
    }

    CalligraphyConfig.initDefault(mCalligraphyConfig);
}

}

0 Answers0