如果你創建一個requestQueue
爲:
requestQueue = Volley.newRequestQueue(mAppContext);
你將不再需要start()
。
根據文檔Volley.RequestQueue
:「創建工作池的默認實例並調用RequestQueue.start()
」。
因此,你可以看到你爲什麼不需要自己打電話start()
。
但是,如果你創建一個requestQueue
的(如圖所示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()
將不得不被調用。 PS:我得到了源代碼本身提供的文檔。 IDE可以毫不費力地提取它們。我只是將鼠標懸停在需要其文檔的方法/類名上,然後按CTRL(在android-studio中)。
有意思,所以'queue'是'start'。這就解釋了爲什麼我的一些斷點被觸發兩次'onResponse' – CQM
也許,請不要使用.start(),看看是否一切順利,並且希望有一天Google可以提供完整的API文檔。它工作的很好,但你需要自己調查一切:) –
我注意到,我幾乎擴展了所有的網絡方法使用'GSON'和'Oauth2' – CQM