How many Volley request queues should be maintained?

android, android-volley

Solution

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.

Problem

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.

Original source

Related problems