Saturday 19 September 2015

PreferenceSetting in Android

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

public class PreferenceSetting {


private String PREF_VALUE = "pref_value";

private static PreferenceSetting store;
SharedPreferences pref;

public static PreferenceSetting getInstance(Context context) {
if (store == null)
store = new PreferenceSetting(context);

return store;
}

private PreferenceSetting(Context context) {
pref = PreferenceManager.getDefaultSharedPreferences(context);
}

public void setValue(String value) {
pref.edit().putString(PREF_VALUE, value).commit();
}

public String getValue() {
return pref.getString(PREF_VALUE, "-");

}


}

No comments:

Post a Comment