In my project i receive data from my server using the "Volley" lib, I made PHP file which returns JSON encoded values and I want to take those values and return them from and not just process them inside the StringRequest,
My code is:
public static void getStatus(final String id, final Marker marker1)
{
// Tag used to cancel the request
String tag_string_req = "req_register";
temp="";
StringRequest strReq = new StringRequest(
Request.Method.POST,
"http://URL/file.php",
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jObj = new JSONObject(response);
String status = jObj.getString("string");
temp = status;
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}) {
@Override
protected Map<String, String> getParams() {
// Posting parameters to getData url
Map<String, String> params = new HashMap<String, String>();
params.put("id", id);
return params;
}
};
// Adding request to request queue
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
}
How can i return the string "status" from this method? (If i change the method to String from void I still couldn't return any values from inside the onResponse (idk why...))? please explain to me why and how can I make it work?