Home » Android » Volley Request Reponse not received in debug mode android studio

Volley Request Reponse not received in debug mode android studio

Posted by: admin November 1, 2017 Leave a comment

Questions:

So i made a StringVolley request which waits for the reponse and then logs the response to log.d().
In a normal run it works fine but when im in debug mode it skips directly to queue.add() without logging the response.

This is my code:

    private void GetResponseFromUrl(String jsonurl)
    {
       // Instantiate the RequestQueue.
       RequestQueue queue = Volley.newRequestQueue(this);

       // Request a string response from the provided URL.
       StringRequest stringRequest = new StringRequest(Request.Method.GET, jsonurl,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        // Display the first 500 characters of the response string.
                        Log.d("Response is: ", response);
                        json = response;
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Log.d("Response is: ", "That doesnt work");
            }
        });
        // Add the request to the RequestQueue.
        queue.add(stringRequest);
    }

Im using API level 25.

EDIT:

The code does get executed but only when all other code is executed so all the code which processes the response is already executed when OnResponse gets called. What can i do about this?

Answers:

Volley Request Response in android studio.

 
     private void GetResponseFromUrl(String jsonurl)
        {
        StringRequest stringRequest = new StringRequest(Request.Method.GET, jsonurl,
                        new Response.Listener() {
                            @Override
                            public void onResponse(String response) {
                  Log.w("-----","response : "+response)

                            }
                        }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Log.d("-----", "Response error :"+error);
                    }
                });
                stringRequest.setRetryPolicy(new DefaultRetryPolicy(60000, 3, 0));
                Volley.newRequestQueue(context).add(stringRequest);
    }