Skip to content

Instantly share code, notes, and snippets.

@luctrudeau
Created July 14, 2015 22: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 luctrudeau/4631eaf4cfe80c29acc4 to your computer and use it in GitHub Desktop.
Save luctrudeau/4631eaf4cfe80c29acc4 to your computer and use it in GitHub Desktop.
Android Object Persistence Recipe
SharedPreferences settings = getSharedPreferences("ETSPref", 0);
List<String> ets = Arrays.asList("I", "Love", "ETS");
// Save Object
SharedPreferences.Editor editor = settings.edit();
editor.putString("ILoveETS", new Gson().toJson(ets));
editor.commit();
// Load Object
List<String> ets2 = new Gson().fromJson(settings.getString("ILoveETS", ""), List.class);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment