Android - Wait for volley response to return

前端 未结 4 806
无人及你
无人及你 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:33

    you cannot return anydata in your getLink() method. Use your code as

    String shortenURL  = ""; // activity global variable
    
    
    
    public void getLink() {
            JsonObjectRequest jsObjRequest = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener() {
    
                        @Override
                        public void onResponse(JSONObject response) {
                            shortenURL = response.getString("url");
                        }
                    }, new Response.ErrorListener() {
    
                        @Override
                        public void onErrorResponse(VolleyError error) {
                            // TODO Auto-generated method stub
    
                        }
                    });
    
                    queue.add(jsObjRequest);
    
    }
    

    You can also see more info at http://arnab.ch/blog/2013/08/asynchronous-http-requests-in-android-using-volley/

提交回复
热议问题