samedi 30 mai 2015

Get main module subclass in library module using dependency injection

I have a base activity class in a library module and a subclass of it in the main module. At run time I want to start this subclass activity using intent in the library module.

One of the way I can load this subclass dynamically through library module is using reflection.

After reading this, I was also thinking of trying out class injection using dependency injection dagger library instead of reflection.

I am looking at this tutorial

Let's assume I have a VehicleModule class in the main module

@Module
public class VehicleModule {

    @Provides @Singleton
    Vehicle provideVehicle(){
        return new Vehicle(new Motor());
    }
}

And VehicleComponent in the library module

@Component(modules = {VehicleModule.class})
public interface VehicleComponent {

    Vehicle provideVehicle();

}

How can I access VehicleModule.class in the library module?





Aucun commentaire:

Enregistrer un commentaire