Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How many Volley request queues should be maintained?

Currently I am maintaining one static Volley request queue as described here:

Instantiating core Volley objects

  private static RequestQueue mReqQueue;

Should there be one and only one static request queue per app? What is the harm in having more than one? for example what if I wanted one request queue just to process twitter requests. And another one for everything else like authentication, image retrieval etc.

like image 319
gitright Avatar asked Jul 17 '13 20:07

gitright


People also ask

What is request queue in volley?

requestQueue is used to stack your request and handles your cache. You need to create this RequestQueue in your application class or in a Singleton class.

How to create Request queue in android?

Start the queue. val requestQueue = RequestQueue(cache, network). apply { start() } val url = "http://www.example.com" // Formulate the request and handle the response. val stringRequest = StringRequest(Request.

What is the use of volley in Android?

Volley is an HTTP library that makes networking for Android apps easier and most importantly, faster. Volley is available on GitHub. Volley offers the following benefits: Automatic scheduling of network requests.


1 Answers

I think Ficus Kirkpatrick said somewhere in his presentation on Volley that optimally, there is only one RequestQueue.

If most of your activities, services and receivers make use of Volley, and you do a lot of switching between them, it makes sense to define a singleton RequestQueue in your Application object so that you don't have to instantiate a new RequestQueue in every acticity / service / receiver onCreate.

However, if you have a lot of activities, and use Volley in only one of them for one request, then you might be better off defining the RequestQueue in just that Activity, or it'll get instantiated in the activities in which you don't use it. This shouldn't hurt functionality, but could hurt memory-wise.


EDIT:

In the volley user group, Ficus said:

RequestQueues are pretty cheap (mostly just threads). We use more than one in our app in order to segregate caches.

Which tells us that it's also a valid use case to use multiple RequestQueues if you need to have separate caches.

like image 72
Maarten Avatar answered Oct 12 '22 13:10

Maarten