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
public static void setStringPreference(Context context, String key, String value) { | |
edit(context, (editor) -> editor.putString(key, value)); | |
} |
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 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); | |
} |
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
import android.content.Context; | |
import android.content.SharedPreferences; | |
import android.preference.PreferenceManager; | |
import android.text.TextUtils; | |
/** | |
* helper for shared prefs - java version | |
*/ |
NewerOlder