Android Open Source - ponyville-live-android String Preference

From Project

Back to project page ponyville-live-android.


The source code is released under:

Apache License

If you think the Android project ponyville-live-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*from  ww w  .  ja  v a2s  .  co m*/
import android.content.SharedPreferences;

public class StringPreference {
  private final SharedPreferences preferences;
  private final String key;
  private final String defaultValue;

  public StringPreference(SharedPreferences preferences, String key) {
    this(preferences, key, null);

  public StringPreference(SharedPreferences preferences, String key, String defaultValue) {
    this.preferences = preferences;
    this.key = key;
    this.defaultValue = defaultValue;

  public String get() {
    return preferences.getString(key, defaultValue);

  public boolean isSet() {
    return preferences.contains(key);

  public void set(String value) {
    preferences.edit().putString(key, value).apply();

  public void delete() {

Java Source Code List