Skip to content

Instantly share code, notes, and snippets.

@tcarrio
Created October 26, 2015 01:28
Show Gist options
  • Save tcarrio/b2fb17dc0a16ef39330b to your computer and use it in GitHub Desktop.
Save tcarrio/b2fb17dc0a16ef39330b to your computer and use it in GitHub Desktop.
Accessing SharedPreferences and setting values
private SharedPreferences sPref;
private final String PREFS = "SharedPreferences";
private final String genderKey = "gender";
private final String activityKey = "activity_level";
private final String timeKey = "time_frame";
private final String nameKey = "name";
private final String ageKey = "age";
private final String heightKey = "height";
private final String weightKey = "weight";
private final String goalKey = "target";
private final String passwordKey = "password";
private final String[] keys
= {genderKey,activityKey,timeKey,nameKey,ageKey,heightKey,weightKey,goalKey,passwordKey};
public void reset() {
// this follows the general steps to open sharedpreferences
sPref = getSharedPreferences(PREFS, Context.MODE_PRIVATE);
// open it up for editing
SharedPreferences.Editor editor = sPref.edit();
for( String s : keys ){
// change key/value stores
editor.put(s,"");
}
//then write the changes
editor.commit();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment