Created
October 26, 2015 01:28
-
-
Save tcarrio/b2fb17dc0a16ef39330b to your computer and use it in GitHub Desktop.
Accessing SharedPreferences and setting values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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