Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Volley deliverResponse not being called

I am using Volley and I see the parseNetworkResponse being called and all ok. The parsing is fine I can see in the logs and I don’t return null. But for some reason the deliverResponse is not being called? How could reason why this can happen or how I could debug this?

Even this:

@Override
        protected Response<Object> parseNetworkResponse(NetworkResponse response) {
            Log.i(“TEST”, "Returning nothing from dummy parseNetworkResponse....");
            Response<Object> jsonResponse = Response.success(new Object(), HttpHeaderParser.parseCacheHeaders(response));
            Log.i("TEST", "Returning nothing....");
            return jsonResponse;
        } 

does not end up in calling the deliverResponse although I can see the logs in the LOGCAT

UPDATE:
I went through the debugger and I end up in the code in NetworkDispatcher (after network-parse-complete and post-response) request.markDelivered(); mDelivery.postResponse(request, response); Then the code in ExecutorDelivery.postResponse is executed:

mResponsePoster.execute(new ResponseDeliveryRunnable(request, response, runnable));

That would eventually call the mRequest.deliverResponse(mResponse.result); but when I add a breakpoint in ResponseDeliveryRunnable.run the code does not break and so I assume that the runnable that would call the deliverResponse is not being run.
Any idea why this could happen?

like image 203
Jim Avatar asked Mar 05 '15 13:03

Jim


People also ask

How to return data from onresponse () of volley to function?

Cancelation request API. It integrates easily with any protocol and comes out of the box with support for raw strings, images, and JSON. So here, We will know how to return data from onResponse () of Volley to our function: 1. Make an interface: first of all, make an interface named VolleyCallback and interface method named onSuccessResponse. 2.

Is volley's onresponse ever called?

The problem I am having is that Volley's onResponse is never called, and hence the data are not parsed and displayed. In logcat, loadNews method is called. I can't see "onResponse called NewsDetails" in logcat, meaning that for some reason not known to me, it's not called

What are the different methods of a volley request?

1- int method – which define your method type which can be GET, POST, PUT, DELETE. 2- String url – this is your url, where you want to send a request and get a response. 3- JSONObject jsonValue – this is your JSON data which will be used when you send the post request. 4- VolleyCallback callback – This is your interface object.

What is volley in Android?

Android volley is a networking library, which was introduced to make networking calls easier, faster without writing a lot of codes. There are many features in Volley: Automatic scheduling of network requests. Multiple concurrent network connections. Transparent disk and memory response caching with standard HTTP cache coherence.


1 Answers

Check your volley logs for clues, as some of the above answerers mentioned. I use an alias to filter volley logs like so:

alias vlog='adb shell setprop log.tag.Volley VERBOSE && adb logcat -Cv threadtime | grep -Ii '\''volley'\'''

When I hit this exact issue, I noticed that the specific requests in question would show the following in the logs:

04-02 17:22:41.309 21639 21639 D Volley  : [1] MarkerLog.finish: (+0   ) [ 1] add-to-queue
04-02 17:22:41.309 21639 21639 D Volley  : [1] MarkerLog.finish: (+10  ) [233] cache-queue-take
04-02 17:22:41.310 21639 21639 D Volley  : [1] MarkerLog.finish: (+0   ) [233] cache-miss
04-02 17:22:41.313 21639 21639 D Volley  : [1] MarkerLog.finish: (+1   ) [234] network-queue-take
04-02 17:22:41.314 21639 21639 D Volley  : [1] MarkerLog.finish: (+227 ) [234] network-http-complete
04-02 17:22:41.314 21639 21639 D Volley  : [1] MarkerLog.finish: (+3   ) [234] network-parse-complete
04-02 17:22:41.315 21639 21639 D Volley  : [1] MarkerLog.finish: (+0   ) [234] post-response
04-02 17:22:41.315 21639 21639 D Volley  : [1] MarkerLog.finish: (+0   ) [ 1] canceled-at-delivery

Scroll to the right and you notice [ 1] canceled-at-delivery in that last line. This is printed by Volley if upon delivery it notices that the original request has been canceled via cancel(). I had an unfortunate code path that was doing this as a "cleanup action" prematurely leading the request being canceled prior to delivery causing Volley to discard it.

From com.android.volley.ExecutorDelivery:93:

    // If this request has canceled, finish it and don't deliver.
    if (mRequest.isCanceled()) {
        mRequest.finish("canceled-at-delivery");
        return;
    }

Hope this helps.

like image 54
scorpiodawg Avatar answered Oct 16 '22 00:10

scorpiodawg