title: How do I use shared preferences in a fragment on Android?
body: <p>I have a fragment and I want to store the Facebook id in a shared preference. I can't write mode private in the get preference function. And also I want to access this shared preference in another fragment. How can I do so?</p>
  
  <p>Here is my code...</p>
  
  <pre><code>Session.openActiveSession(getActivity(), true, new Session.StatusCallback()
  {
      @Override
      public void call(Session session,
                       SessionState state,
                       Exception exception) {
  
          if (session.isOpened()) {
              Request.executeMeRequestAsync(session,new Request.GraphUserCallback() {
  
                  @Override
                  public void onCompleted(GraphUser user, Response response) {
  
                      if (user != null) {
                          t = (TextView)rootView.findViewById(R.id.textView2);
                          p = (ProfilePictureView)rootView.findViewById(R.id.profilePictureView1);
                          p.setProfileId(user.getId());
                          s = user.getName();
                          t.setText(s);
                          s1 = user.getId();
  
                          private void SavePreferences(String key,String value)
                          {
                              SharedPreferences sharedPreferences = getPreferences(MODE_PRIVATE);
                              SharedPreferences.Editor editor = sharedPreferences.edit();
                              editor.putString(key, value);
                              editor.commit();
                          }
  </code></pre>