使用Volley来获取列表中的几个ID的响应

时间:2018-02-23 19:23:31

标签: java android list android-volley

我有一个ID列表,我想获得该列表中每个ID的数据。是否可以使用volley或任何其他网络库而不必调用请求,因为列表正在循环以节省执行时间?

2 个答案:

答案 0 :(得分:0)

是的,你可以,只有一个请求,如果响应包含ID,那么你可以在JSON解析期间获取列表ID。

答案 1 :(得分:0)

所以这就是我迄今为止所做的工作。要发送每个ID的多个网络请求,需要一个新的RequestQueue构造函数(用于齐射)。 `RequestQueue mRequestQueue = Volley.newRequestQueue(mContext);

        // Instantiate the cache
        Cache cache = new DiskBasedCache(mContext.getCacheDir(), 1024 * 1024); // 1MB cap

        // Set up the network to use HttpURLConnection as the HTTP client.
        BasicNetwork network = new BasicNetwork(new HurlStack());

        mRequestQueue = new RequestQueue(cache, network, 29);
//The Integer 29 indicate the number of requests, 
//hence, the number of concurrent threads volley will run on its Looper and 
//Handler.

        // Start the queue
        mRequestQueue.start();

       //Make request here

我希望它对任何人都有帮助。