title: How to create a sharedPreference class in Android
body: <p>I am learning android and trying to figure out the best way to do a shared preference class. This is an example of a sharedPreference class;</p>
  
  <pre><code> public static final String MyPREFERENCES = "MyPrefs" ;
     public static final String Name = "nameKey";
     public static final String Phone = "phoneKey";
     public static final String Email = "emailKey";
     SharedPreferences sharedpreferences;
  </code></pre>
  
  <p>I am trying to turn that into a class similar to something like this.</p>
  
  <pre><code>package pesa.sharedpreferencedemo.Utils;
  
  import android.content.Context;
  import android.content.SharedPreferences;
  import android.content.SharedPreferences.Editor;
  import android.preference.PreferenceManager;
  
  /**
   * Created by mpan0590 on 9/19/2016.
   */
  
  public class SharedPreference {
  
          public static final String PREFS_NAME = "PESASEND_PREFS";
          public static final String PREFS_KEY = "AOP_PREFS_String";
  
  
          public SharedPreference() {
              super();
          }
  
          public void save(Context context, String text) {
              SharedPreferences settings;
              Editor editor;
  
              //settings = PreferenceManager.getDefaultSharedPreferences(context);
              settings = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE); //1
              editor = settings.edit(); //2
  
              editor.putString(PREFS_KEY, text); //3
  
              editor.commit(); //4
          }
  
          public String getValue(Context context) {
              SharedPreferences settings;
              String text;
  
              //settings = PreferenceManager.getDefaultSharedPreferences(context);
              settings = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
              text = settings.getString(PREFS_KEY, null);
              return text;
          }
  
          public void clearSharedPreference(Context context) {
              SharedPreferences settings;
              Editor editor;
  
              //settings = PreferenceManager.getDefaultSharedPreferences(context);
              settings = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
              editor = settings.edit();
  
              editor.clear();
              editor.commit();
          }
  
          public void removeValue(Context context) {
              SharedPreferences settings;
              Editor editor;
  
              settings = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
              editor = settings.edit();
  
              editor.remove(PREFS_KEY);
              editor.commit();
          }
  }
  </code></pre>
  
  <p>Is there a way I can do the same for the above example, I am new to this sharedpreference/android stuff and its a bit confusing. I basically just want to create a sharedpreference class, where you can add new values, edit current values and remove other values. The code I have shown here is not mine but from tutorials that I have found online.</p>