Android - Wait for volley response to return

前端 未结 4 817
无人及你
无人及你 2020-12-08 10:39

I need execute a Volley request and wait for the response to parse it and return it, but have no idea on how to achieve this. Can someone help?

What I have now is th

4条回答
  •  感动是毒
    2020-12-08 11:15

    You can do this using the future concept

     RequestFuture jsonObjectRequestFuture = RequestFuture.newFuture();
        JsonObjectRequest request = new JsonObjectRequest(ServiceUrl.BFF_BASE_URL + path, (JSONObject) postBody, jsonObjectRequestFuture, jsonObjectRequestFuture);
    requestQueue.add(request);
    JSONObject jsonObject = jsonObjectRequestFuture.get(30, TimeUnit.SECONDS);
    

提交回复
热议问题