I\'ve been stuck on this very simple problem for hours now and Ive been unable to find any suitable solutions through google.
I am trying to use the SharedPreference
Where do you instantiate your Model class?
Just pass either a context or the SharedPreferences to the constructor:
public class Model {
private final Context context;
private final SharedPreferences sharedPrefs;
public Model(Context context) {
this.context = context;
sharedPrefs = context.getSharedPreferences("name", 0);
}
private String doSomething(){
return sharedPrefs.getString("key", "defValue");
}
}