Schwarz Software
Schwarz Software

Reputation: 1552

Pass details to volley inner class

This answer should be simple but I need help. I add a url call to Volley and on error response I need to know what the URL was that the error is for, I may have 50 different URL's in a single queue for example so I want to know which one of the 50 returned the error.

Here is my code:

    public void upload(String passurl) {

    StringRequest stringRequest;
    // Request a string response
    stringRequest = new StringRequest(Request.Method.GET, passurl,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    Log.d(TAG,"Send successful");
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
                //***I want the URL that failed here!
                error.printStackTrace();
        }
    });
    stringRequest.setRetryPolicy(new DefaultRetryPolicy(30000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
    // Add the request to the queue
    stringRequest.setShouldCache(false);
    stringRequest.setTag(TAG);
    if (mRequestQueue == null) {
        mRequestQueue = Volley.newRequestQueue(this.getApplicationContext());
        mRequestQueue.start();
    }
    mRequestQueue.getCache().clear();
    mRequestQueue.add(stringRequest);
}

Upvotes: 0

Views: 76

Answers (1)

AnthonyK
AnthonyK

Reputation: 473

To expand on @Levon's answer make passurl final for example method(final String passurl)

Upvotes: 2

Related Questions