你不能只是按顺序写每个请求并等待每个成功响应后执行每个请求…你必须在第一个服务响应中调用第二个请求…即
public void firstServiceCall(String url)
{
JsonObjectRequest jsonObjReq = new JsonObjectRequest(
Request.Method.GET, url, null,
new Response.Listener() {
@Override
public void onResponse(JSONObject response) {
int membershipid=response.getInt("membershipid");
//suppose the membershipid comes under main json with key "membershipid"
secondServiceCall(membershipid,);
// on the response of first service ... call to the second service ... and continue so on... if required
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
Volley.newRequestQueue(getApplicationContext()).add(jsonObjReq);
}
public void secondServiceCall(int membershipid,String url)
{
// use this var membershipid acc to your need ...
JsonObjectRequest jsonObjReq = new JsonObjectRequest(
Request.Method.GET, url, null,
new Response.Listener() {
@Override
public void onResponse(JSONObject response) {
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
Volley.newRequestQueue(getApplicationContext()).add(jsonObjReq);
}
also the request call is asynchronous hence… the other process won’t wait for service call to finish…hence your second service starts before the first service response