Skip to content

Instantly share code, notes, and snippets.

@Sparker0i
Created July 9, 2016 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sparker0i/4d3f4bfe3d5f86f98d83bdf1784ef78c to your computer and use it in GitHub Desktop.
Save Sparker0i/4d3f4bfe3d5f86f98d83bdf1784ef78c to your computer and use it in GitHub Desktop.
import android.app.Activity;
import android.content.SharedPreferences;
public class CityPreference {
SharedPreferences prefs;
public CityPreference(Activity activity){
prefs = activity.getPreferences(Activity.MODE_PRIVATE);
}
// If the user has not chosen a city yet, return
// Sydney as the default city
String getCity(){
return prefs.getString("city", "Sydney");
}
void setCity(String city) {
prefs.edit().putString("city", city).commit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment