【发布时间】:2015-06-17 13:57:03
【问题描述】:
我尝试在当前的 volley 请求中执行一个新的 volley 请求,但是当新的请求被调用时,它并没有进入 onrespond 方法。
新请求应在第一个结束之前执行。 (后进先出)
我怎样才能成功执行新的请求?
private void makeJsonObjectRequest() {
ac = new AppController();
final JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET,
url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d("test", response.toString());
try {
// Parsing json object response
// response will be a json object
JSONArray name = response.getJSONArray("data");
for (int i = 0; i < name.length(); i++) {
JSONObject post = (JSONObject) name.getJSONObject(i);
try {
objectid = post.getString("object_id");
newRequest(objectid);
}
catch (Exception e) {
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d("test", "Error: " + error.getMessage());
}
});
// Adding request to request queue
ac.getInstance().addToRequestQueue(jsonObjReq);
}
【问题讨论】:
-
将 Priority.HIGH 设置为内部请求,将 Priority.LOW 设置为外部请求
标签: android json android-volley