Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.yundin.styleruhw2;
- import android.content.Context;
- import android.content.SharedPreferences;
- public final class SharedPreferencesHelper {
- private static final String SP_NAME = "my_app_sp";
- private static final String NAME_KEY = "sp_name";
- private static final String SURNAME_KEY = "sp_lastname";
- private static final String GROUP_KEY = "sp_group";
- private static final String EDIT_KEY = null;
- private static SharedPreferences sharedPreferences;
- public static SharedPreferences getSharedPreferences() {
- return sharedPreferences;
- }
- public static void init(Context context) {
- sharedPreferences = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
- }
- public static String getName() {
- return sharedPreferences.getString(NAME_KEY, null);
- }
- public static String getSurname() {
- return sharedPreferences.getString(SURNAME_KEY, null);
- }
- public static String getGroup() {
- return sharedPreferences.getString(GROUP_KEY, null);
- }
- public static String getEdit() {
- return sharedPreferences.getString(EDIT_KEY, null);
- }
- public static void setName(String name) {
- sharedPreferences.edit()
- .putString(NAME_KEY, name)
- .apply();
- }
- public static void setSurname(String surname) {
- sharedPreferences.edit()
- .putString(SURNAME_KEY, surname)
- .apply();
- }
- public static void setGroup(String group) {
- sharedPreferences.edit()
- .putString(GROUP_KEY, group)
- .apply();
- }
- public static void setEdit(String edit) {
- sharedPreferences.edit()
- .putString(EDIT_KEY, edit)
- .apply();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement