0
我剛開始使用Volley的庫進行http調用,並且我嘗試使用RequestFuture類進行同步請求,但是我無法做出簡單請求。任何想法我做錯了什麼?Volley同步請求
RequestQueue requestQueue = Volley.newRequestQueue(this);
String url = "http://myapi-oh.fr/v2/podcasts/x/shows/" + points.get(0).getShowId() + "/streams";
RequestFuture<JSONObject> future = RequestFuture.newFuture();
JsonObjectRequest request = new JsonObjectRequest(url, null, future, future);
requestQueue.add(request);
try {
JSONObject response = future.get(10, TimeUnit.SECONDS);; // this will block (forever)
points.get(0).setStreamUrl(response.getJSONArray("result").getJSONObject(0).getString("url"));
} catch (InterruptedException e) {
Log.d(TAG, "error : " + e);
// exception handling
Log.d(TAG, "error : " + e);
} catch (ExecutionException e) {
// exception handling
Log.d(TAG, "error : " + e);
} catch (JSONException e) {
e.printStackTrace();
Log.d(TAG, "error : " + e);
} catch (TimeoutException e) {
e.printStackTrace();
}
是的,我已經在其他情況下做了這些,但是這次我想讓它同步! – krakig