Source:
public void attemptLogin(View view){ final Intent intent = new Intent(this, MainActivity.class); EditText email = (EditText) findViewById(R.id.username); EditText pass = (EditText) findViewById(R.id.pass); final Button loginButton = (Button) findViewById(R.id.login_button); loginButton.setEnabled(false); final String emailString = email.getText().toString(); final String passString = pass.getText().toString(); HashMap<String, String> params = new HashMap<String, String>(); params.put("email", emailString); params.put("password", passString); JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, url, new JSONObject(params), new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject jsonObject) { SharedPreferences prefs = getSharedPreferences(PREFS, 0); SharedPreferences.Editor editor = prefs.edit(); try { String token = jsonObject.getString("token"); editor.putString("email", emailString); editor.putString("password", passString); editor.putString("token", token); editor.commit(); intent.putExtra("token", jsonObject.getString("token")); LoginActivity.this.finish(); startActivity(intent); } catch (JSONException err) { Log.d("JSON Exception: ", err.getMessage()); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError volleyError) { Log.d("Volley Error", new String(volleyError.networkResponse.data)); Context context = getApplicationContext(); String message; if (volleyError instanceof NetworkError){ message = "Network Error. Please try again later."; } else { try { JSONObject response = new JSONObject(new String(volleyError.networkResponse.data)); message = (String) response.get("message"); } catch (Exception e) { message = "Unknown Error"; } } Toast toast = Toast.makeText(context, message, Toast.LENGTH_SHORT); toast.show(); loginButton.setEnabled(true); } }); queue.add(request); }

Target:
public void attemptLogin(View view){ final Intent intent = new Intent(this, MainActivity.class); EditText email = (EditText) findViewById(R.id.username); EditText pass = (EditText) findViewById(R.id.pass); final Button loginButton = (Button) findViewById(R.id.login_button); loginButton.setEnabled(false); final String emailString = email.getText().toString(); final String passString = pass.getText().toString(); HashMap<String, String> params = new HashMap<String, String>(); params.put("email", emailString); params.put("password", passString); JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, url, new JSONObject(params), new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject jsonObject) { SharedPreferences prefs = getSharedPreferences(PREFS, 0); SharedPreferences.Editor editor = prefs.edit(); try { String token = jsonObject.getString("token"); editor.putString("email", emailString); editor.putString("password", passString); editor.putString("token", token); editor.commit(); intent.putExtra("token", jsonObject.getString("token")); LoginActivity.this.finish(); startActivity(intent); } catch (JSONException err) { Log.d("JSON Exception: ", err.getMessage()); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError volleyError) { Context context = getApplicationContext(); String message; if (volleyError instanceof NetworkError){ message = "Network Error. Please try again later."; } else { try { JSONObject response = new JSONObject(new String(volleyError.networkResponse.data)); message = (String) response.get("message"); } catch (Exception e) { message = "Unknown Error"; } } Toast toast = Toast.makeText(context, message, Toast.LENGTH_SHORT); toast.show(); loginButton.setEnabled(true); } }); queue.add(request); }