Question: Here is my code:

```
                            new Response.Listener<String>() {

                                @Override
                                public void onResponse(String response) {
                                    try {
                                        JSONObject jsonObject = new JSONObject(response);
                                        String status = jsonObject.getString("success");

                                        if (status.equals("1")) {
                                            Toast.makeText(getApplicationContext(), "Login Successfully", Toast.LENGTH_LONG).show();
                                            Intent i = new Intent(LoginActivity.this, MainActivity.class);
                                            SharedPreferences.Editor editor = context.getSharedPreferences("UserDetail", 0).edit();
                                            editor.clear();
                                            editor.putString("mobile",edtmobilenumber.getText().toString());
                                            editor.commit();
                                            startActivity(i);
                                            finish();

                                        }
                                        else if(status.equals("0")){
                                            Toast.makeText(getApplicationContext(), "Invalid Credentials", Toast.LENGTH_LONG).show();
                                        }

                                    } catch (JSONException e) {
                                        e.printStackTrace();
                                    }
                                }
                            }, new Response.ErrorListener() {

                        @Override
                        public void onErrorResponse(VolleyError error) {
                            pDailog.dismiss();

                            Toast.makeText(LoginActivity.this, error.toString(), Toast.LENGTH_SHORT).show();
                        }
                    }) {

```

Answer: 
**FOR SAVING VALUES**

```
SharedPreferences.Editor editor = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE).edit();
editor.putString("name", "Hello");
editor.putInt("value", 12);
editor.commit();

```

**FOR FETCHING DATA BACK**

```
SharedPreferences prefs = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE); 
String restoredText = prefs.getString("text", null);

if (restoredText != null) {
String name = prefs.getString("name", "No name defined");//"No name defined" is the default value.
int idName = prefs.getInt("value", 0); //0 is the default value.
}

```
You can try out the following code :

First declare:

```
SharedPreferences myPreference;

```

In onCreate():

```
myPreference =PreferenceManager.getDefaultSharedPreferences(this);

```

In OnResponse():

```
myPreference.edit().putString("mobile",edtmobilenumber.getText().toString()).apply();

```