How do I use the Volley network request queue?
Asked Answered
I

2

8

I .add( new network calls to my Volley Request Queue which I have created as a singleton as suggested. But I always immediately .start() these network calls. This is always done as an action in an activity or a fragment.

The add method cannot even be chained into a start method, like .add(new volley request).start()

So this assumes I am actually managing (or wanting to manage) a network queue somewhere, outside of the way Volley handles its queue, I guess. Should I be sending these things to an IntentService and listening for the IntentService to send a response back to my Fragment/Activity?

Intuitional answered 28/2, 2014 at 21:49 Comment(0)
S
11

As a volley user I can tell you that I have never called .start() method. all the requests i've added to the queue started automatically, I used singleton class like you did.

Spoonful answered 28/2, 2014 at 22:3 Comment(11)
interesting, so queue is start. That explains why some of my breakpoints get triggered twice onResponseIntuitional
Probably, try not using the .start() and see if all goes well, and lets hope that some day Google will provide full API documentation. It works great but you need to investigate everything by yourself :)Spoonful
I've noticed, I've extended practically all of the network methods to use GSON and Oauth2 effectivelyIntuitional
As soon as the queue is initialized it will process any requests added to it. Ie. RequestManager.init(this);Wasserman
According to docs of Volley.RequestQueue : "Creates a default instance of the worker pool and calls RequestQueue.start() on it." Hence you can see why you never needed to call start() yourself.Early
But when I add to queue it takes about 5seconds before I receive and response.i m trying to figure out where the delay wasVirginiavirginie
Check internet connection (maybe slow or something), you can also test the request with postman extension in chrome browserSpoonful
The link seems dead.Ligule
@UdiOshi hi there, why you have provided the link? it's dead already.Finochio
@amitpandya comment was 3 years old. edited and removed it. concept stays the sameSpoonful
@UdiOshi thanx for your response.Finochio
E
12

If you create a requestQueue as:

requestQueue = Volley.newRequestQueue(mAppContext);

you will not need start().

According to docs of Volley.RequestQueue : "Creates a default instance of the worker pool and calls RequestQueue.start() on it."

Hence you can see why you never needed to call start() yourself.

However, if you create a requestQueue as (as shown in the official reference):

RequestQueue mRequestQueue;

// Instantiate the cache
Cache cache = new DiskBasedCache(getCacheDir(), 1024 * 1024); // 1MB cap

// Set up the network to use HttpURLConnection as the HTTP client.
Network network = new BasicNetwork(new HurlStack());

// Instantiate the RequestQueue with the cache and network.
mRequestQueue = new RequestQueue(cache, network);

// Start the queue
mRequestQueue.start();

start() will have to be called.

PS: I get the documentation as provided in the source code itself. IDEs are able to extract them effortlessly. I just hover over the method/class name whose document I need and press CTRL (in android-studio).

Early answered 5/9, 2014 at 15:26 Comment(0)
S
11

As a volley user I can tell you that I have never called .start() method. all the requests i've added to the queue started automatically, I used singleton class like you did.

Spoonful answered 28/2, 2014 at 22:3 Comment(11)
interesting, so queue is start. That explains why some of my breakpoints get triggered twice onResponseIntuitional
Probably, try not using the .start() and see if all goes well, and lets hope that some day Google will provide full API documentation. It works great but you need to investigate everything by yourself :)Spoonful
I've noticed, I've extended practically all of the network methods to use GSON and Oauth2 effectivelyIntuitional
As soon as the queue is initialized it will process any requests added to it. Ie. RequestManager.init(this);Wasserman
According to docs of Volley.RequestQueue : "Creates a default instance of the worker pool and calls RequestQueue.start() on it." Hence you can see why you never needed to call start() yourself.Early
But when I add to queue it takes about 5seconds before I receive and response.i m trying to figure out where the delay wasVirginiavirginie
Check internet connection (maybe slow or something), you can also test the request with postman extension in chrome browserSpoonful
The link seems dead.Ligule
@UdiOshi hi there, why you have provided the link? it's dead already.Finochio
@amitpandya comment was 3 years old. edited and removed it. concept stays the sameSpoonful
@UdiOshi thanx for your response.Finochio

© 2022 - 2024 — McMap. All rights reserved.