Let's say i have two modules how would i share modules from one ActivityModule to another module called ModelModule. Here is what i have so far:
@Module(
includes = ActivityModule.class,
library = true,
injects= {
MainModel.class,
})
public class ModelModule {
}
and here is the activityModule:
@Module(
library = true,
injects= {
main.class,
MyIntentService.class,
})
public class ActivityModule {
//application context
Context context;
public ActivityModule(Context context){
this.context = context;
}
@Provides
@Singleton
AudioManager provideAudioManager(){return (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);}
@Provides
@Singleton
Vibrator provideVibratorManager(){return (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);}
@Provides
SharedPreferences provideSharedPref(){
return PreferenceManager
.getDefaultSharedPreferences(context);
}
}
Here is how im adding the module to the object graph:
public class MainApplication extends Application {
private ObjectGraph objectGraph;
@Override
public void onCreate() {
super.onCreate();
Object[] modules = getModules().toArray();
objectGraph = ObjectGraph.create(modules);
// objectGraph.inject(this);
}
protected List<Object> getModules() {
return Arrays.<Object>asList(
new ActivityModule(this),
new ModelModule()
);
}
public void inject(Object object) {
objectGraph.inject(object);
}
public void addtoGraph(Object object) {
objectGraph.plus(object);
}
}
My issue is each time i try to use preference which should be provided by ActivityModule, from the MainModel class preferences is null. I used the includes keyword in the ModelModule.java class as i thought that would then give me access to the ActivityModule's provided methods.