title: Shared Preferences on Android Development
body: <p>i have a problem on my shared prefs, i have my two activities and this is my code for my shared prefs.</p>
  
  <pre><code>public class SaveSharedPreferences {
  
  static final String PREF_USER_NAME= "";
  static final String PREF_PROPIC= "";
  
  static SharedPreferences getSharedPreferences(Context ctx) {
      return PreferenceManager.getDefaultSharedPreferences(ctx);
  }
  
  public static void setUserName(Context ctx, String userName)
  {
      SharedPreferences.Editor editor = getSharedPreferences(ctx).edit();
      editor.putString(PREF_USER_NAME, userName);
      editor.commit();
  }
  
  public static String getUserName(Context ctx)
  {
      return getSharedPreferences(ctx).getString(PREF_USER_NAME, "");
  }
  
  public static void setProfile(Context ctx, String profile)
  {
      SharedPreferences.Editor editor = getSharedPreferences(ctx).edit();
      editor.putString(PREF_PROPIC, profile);
      editor.commit();
  }
  
  public static String getProfile(Context ctx)
  {
      return getSharedPreferences(ctx).getString(PREF_PROPIC, "");
  }
  
  public static void clearPrefs(Context ctx){
      SharedPreferences.Editor editor = getSharedPreferences(ctx).edit();
      editor.clear();
      editor.commit();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Everytime i log in on my main activity to next activity, i always add a string value to "PREF_USER_NAME" and it stores as you can see above. So when i successfully log in, i call "PREF_PROFILE" with no value. But at the time i call it, the value im getting is the value from "PREF_USER_NAME". So thats my problem, i dont see anything wrong. So can somebody help me, i appreciate your comments and suggestion thanks!</p>