Skip to content

Instantly share code, notes, and snippets.

@krupalshah
Last active June 7, 2017 15:58
Show Gist options
  • Save krupalshah/7d408a8ca27649c04d81c1ec1edd5ca2 to your computer and use it in GitHub Desktop.
Save krupalshah/7d408a8ca27649c04d81c1ec1edd5ca2 to your computer and use it in GitHub Desktop.
helper for shared prefs - java version - Refactoring step 1
private static void edit(Context context, Performer<SharedPreferences.Editor> performer) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = sharedPreferences.edit();
performer.performOperation(editor);
editor.apply();
}
public interface Performer<T> {
void performOperation(T victim);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment