Actually i am new to dependency injection and dagger, i have been writing boiler plate code all these time and am trying to learn dagger
I have a global class to save preference values
@Module(injects = AppPrefes.class)
public class AppPrefes {
private SharedPreferences appSharedPrefs;
private Editor prefsEditor;
public AppPrefes(Context context, String Preferncename) {
this.appSharedPrefs = context.getSharedPreferences(Preferncename,
Activity.MODE_PRIVATE);
this.prefsEditor = appSharedPrefs.edit();
}
/****
*
* getdata() get the value from the preference
*
* */
@Provides
public String getData(String key) {
return appSharedPrefs.getString(key, "");
}
/****
*
* SaveData() save the value to the preference
*
* */
@Provides
public void SaveData(String Tag, String text) {
prefsEditor.putString(Tag, text);
prefsEditor.commit();
}
}
How could i possibly inject this class in My activity In my activity oncreate i have put like this
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ObjectGraph objectGraph = ObjectGraph.create();
AppPrefes app = objectGraph.get(AppPrefes.class);
}
but how should i pass dependency i.e the context and the preference name to AppPrefes class,i am completely new to dependency injection please correct me if i am wrong Since dagger documentation seems to be little tough for me am asking this question.