I have written a class which contains all the methods for volley requests such as GET,POST,PUT. I want to return value response from those methods. I am unable to find a solution since I can't return the response from overriden methods such as onErrorResponse and parseNetworkResponse. The code for PUT method is and I want to return the status code from this method-
public static int volleyPutRequest(URL url, JSONObject jsonObject, final Context context) {
// Object of request queue
RequestQueue requestQueue;
// Getting the instance of request queue
requestQueue = CustomVolleyRequestQueue.getInstance(context).getRequestQueue();
// Making a JSON request to send the json object to the server
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.PUT,
url.toString(), jsonObject, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d("OnResponse", response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("OnErrorResponse", error.toString());
}
}){
@Override
protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) {
Log.e("ParseNetworkResponse", String.valueOf(response.statusCode));
return super.parseNetworkResponse(response);
}
};
// Adding the request to the RequestQueue
requestQueue.add(jsonObjectRequest);
}