Volley REST API get request error when response has more than 100 JSON objects

I am writing an application which shows some data from a REST service written in C# in Visual Studio. The REST API is written by my team. The response is usually a JSON Array with JSON Objects as its children which essentially represent the data being returned. I am using Volley library to process the request, parse the response and put it in a Recycler View list. The response comes up just fine when the number of JSON Objects, or lets say the length of the returned JSON array is less than 100. Whenever, it is more than 100, the response doesn't come to the application. Even the JSONException stack trace shows not anything helpful. I tried testing the API in Postman, and it works fine regardless of the number of JSON objects returned. Could you please help me in figuring out if there is any routine which we can override to fix this? Do let me know if you want to have a look at the code itself.

Thanks, Atul

2 answers

  • answered 2018-05-16 05:51 Md. Sajedul Karim

    I think it crashes because of timeOutError. When volley has to parse a large amount of data, you should set the timeout for your volley request. Default timeout is 2500ms, set it to 10000ms or higher it'll work for ex.

    strReq.setRetryPolicy(new DefaultRetryPolicy(10000,
    DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
    

    It will not consume all the time that you allotted, but it will be disconnected once all the data is fetched

    timeoutError will not give you crash, but onErrorResponse would be called, please make sure that tables that you are going to insert into were created before making insert operation.

    More info visit here , here and for largeHeap

  • answered 2018-05-16 06:11 Vivek Shah

    You can set timeout of the volley Check this https://stackoverflow.com/a/17179436/1213735

    Better use retrofit which is far better then volley.