title: how to retrive shared preferences from another class without activity ANDROID
body: <pre><code>package com.example.win7.simpleloginapp;
  
  
  
  public class ServerRequest  {
  
  ProgressDialog progressDialog;
  public static final int CONNECTION_TIMEOUT = 1000 * 15;
  public static final String SERVER_ADDRESS =  "ekinidris.site40.net";
  
  final static String TAG_USER = "user";
  JSONArray user;
  JSONParser jsonParser = new JSONParser();
  // Create object of SharedPreferences.
  SharedPreferences sharedPref1 = PreferenceManager.getDefaultSharedPreferences(this);
  public ServerRequest(Context context) {
      progressDialog = new ProgressDialog(context);
      progressDialog.setCancelable(false);
      progressDialog.setTitle("Processing..");
      progressDialog.setMessage("Please Wait....");
  }
  
  public void storeUserDataInBackground(user user, GetUserCallback userCallback) {
      progressDialog.show();
      new StoreUserDataAsyncTask(user, userCallback).execute();
  }
  
  public void fetchUserDataInBackground(user user, GetUserCallback callBack) {
      progressDialog.show();
      new fetchUserDataAsyncTask(user, callBack).execute();
  }
  
  
  
  
  
  
  public class fetchUserDataAsyncTask extends AsyncTask&lt;Void, Void, user&gt; {
      user user;
      GetUserCallback userCallback;
  
      public fetchUserDataAsyncTask(user user, GetUserCallback userCallback) {
          this.user = user;
          this.userCallback = userCallback;
      }
  
      @Override
      protected user doInBackground(Void... params) {
          ArrayList&lt;NameValuePair&gt; dataToSend = new ArrayList&lt;&gt;();
          dataToSend.add(new BasicNameValuePair("username", user.username));
          dataToSend.add(new BasicNameValuePair("password", user.password));
  
  
          HttpParams httpRequestParams = new BasicHttpParams();
          HttpConnectionParams.setConnectionTimeout(httpRequestParams, CONNECTION_TIMEOUT);
          HttpConnectionParams.setSoTimeout(httpRequestParams, CONNECTION_TIMEOUT);
          HttpClient client = new DefaultHttpClient(httpRequestParams);
          HttpPost post = new HttpPost("http://mysyshcms.cloudapp.net:1005/fetchUserData.php");
  
          user returnedUser = null;
          try {
              post.setEntity(new UrlEncodedFormEntity(dataToSend));
              HttpResponse httpResponse = client.execute(post);
  
              HttpEntity entity = httpResponse.getEntity();
              String result = EntityUtils.toString(entity);
              JSONObject jObject = new JSONObject(result);
  
              if(jObject.length()==0)
              {
                  returnedUser = null;
  
              }
              else
              {
  
  
  
                  String Name1 = jObject.getString("Name");
  
  
                  //now get Editor
                  SharedPreferences.Editor editor = sharedPref1.edit();
                  //put your value
                  editor.putString("username", Name1);
  
                  //commits your edits
                  editor.commit();
                  returnedUser = new user(user.username, user.password);
  
              }
  
  
          } catch (Exception e) {
              e.printStackTrace();
          }
  
          return returnedUser;
      }
  
      @Override
      protected void onPostExecute(user returnedUser) {
          progressDialog.dismiss();
          userCallback.done(returnedUser);
          super.onPostExecute(returnedUser);
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>i have <code>ServerRequest</code> class which is not an <code>activity</code> . In  public class <code>fetchUserDataAsyncTask</code> i want to make a shared preferences . this is because i want to pass data that i get from database to another activity (<code>MainActivity</code>)</p>
  
  <pre><code>public class MainActivity extends  ActionBarActivity  {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      ActionBar actionBar = getSupportActionBar();
      actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#689a92")));
      actionBar.setDisplayUseLogoEnabled(true);
      actionBar.setDisplayShowHomeEnabled(true);
  
      setContentView(R.layout.activity_main);
  
     SharedPreferences sharedPref1 = PreferenceManager.getDefaultSharedPreferences(this);
      String userName = sharedPref1.getString("username", "NOT AVAILABLE");
      etUsername.setText(userName);
  </code></pre>
  
  <p>but i keep getting "NOT AVAILABLE" instead of Name1 that i declare in server request . How to solve this ?</p>