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?
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. Then only you can use the same requestQueue from multiple activities.
RequestQueue is where all the requests are queued up that has to be executed, it also manages the worker threads and maintain network call in the background also it handles reading from and writing to the cache and also parsing the response and delivering the parsed response to mainthread.
Volley automatically schedules all network requests such as fetching responses for image from web. Volley provides transparent disk and memory caching. Volley provides powerful cancellation request API for canceling a single request or you can set blocks of requests to cancel.
requestQueue = new RequestQueue(cache, network); // Start the queue requestQueue. start(); String url = "http://www.example.com"; // Formulate the request and handle the response. StringRequest stringRequest = new StringRequest(Request.
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.
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