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.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With