I .add(
对我的 Volley 请求队列的新网络调用,我已按照建议将其创建为单例。但我总是立刻.start()
这些网络调用。这始终作为活动或片段中的操作来完成。
The add
方法甚至不能链接到start
方法,比如.add(new volley request).start()
因此,这假设我实际上正在管理(或想要管理)某个地方的网络队列,我想,这超出了 Volley 处理其队列的方式。我是否应该将这些内容发送到 IntentService 并侦听 IntentService 将响应发送回我的片段/活动?
如果您创建一个requestQueue
as:
requestQueue = Volley.newRequestQueue(mAppContext);
你不需要start()
.
根据文档Volley.RequestQueue
:“创建工作池的默认实例并调用RequestQueue.start()
on it."
因此你可以明白为什么你从来不需要打电话start()
你自己。
但是,如果您创建一个requestQueue
如(如官方参考):
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()
将不得不被调用。
PS:我得到了源代码本身提供的文档。 IDE 能够毫不费力地提取它们。我只需将鼠标悬停在我需要其文档的方法/类名称上,然后按 CTRL(在 android-studio 中)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)