I am new to Android and I want your help regarding StringRequestVolley. In my project I will be calling several API's. For that I have created a method named ProcessAPIRequest. For this I will be passing URL as parameter. Here is my code snippet of function.
private static String iResponse="";
public static String ProcessAPIRequest(String pURL, Context pContext){
iResponse="";
StringRequest stringRequest = new StringRequest(pURL,
new Response.Listener<String>() {
@Override
public void onResponse(String strResponse) {
iResponse=strResponse;
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
//error.networkResponse;
//Log.e("error", "" + error);
}
});
RequestQueue requestQueue = Volley.newRequestQueue(pContext);
requestQueue.add(stringRequest);
return iResponse;
}
The problem I am facing is whenever I call this method I am getting empty Response. public void onResponse method is firing after the response is returned. I want response should be returned once it gets the result.