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 the Shared Preference value as a String

```
SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(context);

    public void saveValue(String key, String value) {       
        SharedPreferences.Editor saveValue = prefs.edit();
        saveValue.putString(key, value);
        saveValue.apply();
    }

```

For getting the stored value

```
 public String getValue(String key, String defaultValue) {           
        return prefs.getString(key, defaultValue);
    }

```
from documentation:

> 
> Create a new Editor for these preferences, through which you can make modifications to the data in the preferences and atomically commit those changes back to the SharedPreferences object.
> 
> 
>