I've been playing around with Transfuse (http://androidtransfuse.org/) and am now trying to tackle SharedPreferences
. The documentation makes this seem pretty straight forward:
@Activity
public class Example{
@Inject @Preference(value = "favorite_color", default = "green")
String favColor;
}
However, as I understand it, SharedPreferences
are retrieved by name, not just by key. So, how does Transfuse know the name of the SharedPreferences
file I'm trying to access?
I've tried something like this to no avail:
@Activity
public class MainActivity{
public static final String PREF_NAME = "pref_name";
@Inject
android.app.Activity mActivity;
@Inject @Preference(value = PREF_NAME, defaultValue = "")
String mPreference;
@Inject @View(R.id.preference)
EditText mPreferenceEditText;
@RegisterListener(R.id.button_2)
android.view.View.OnClickListener mSavePrefListener = new android.view.View.OnClickListener() {
@Override
public void onClick(android.view.View v) {
String val = mPreferenceEditText.getText().toString();
mActivity.getSharedPreferences("the_shared_prefs", Context.MODE_PRIVATE)
.edit()
.putString(PREF_NAME, val)
.apply();
}
};
@OnResume
private void displayPrefText(){
mPreferenceEditText.setText(mPreference);
}
}
Thanks for your help!