0

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);

}

  • Check [this](http://programminglife.io/android-volley-synchronous-request/) post. – Jyotman Singh Mar 07 '16 at 09:21
  • Please read my answer at http://stackoverflow.com/questions/32375295/android-how-to-return-async-jsonobject-from-method-using-volley/32379539#32379539 and http://stackoverflow.com/questions/32672942/android-volley-library-do-we-always-have-to-repeat-response-listener-and-respon/32674056#32674056 hope it helps! – BNK Mar 07 '16 at 09:25

0 Answers0