How do I use the Volley network request queue?

后端 未结 2 805
执笔经年
执笔经年 2021-01-02 08:06

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 netw

相关标签:
2条回答
  • 2021-01-02 08:16

    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).

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题