I have the following code which works to make a call and receives xml.
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
// Do something with the response
Log.e(TAG, "response from RRSendCarerLocation = " + response);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// Handle error
Log.e(TAG, "error: RRSendCarerLocation = " + error);
}
});
rq.add(stringRequest);
.
The problem i have is, this works fine when called from an Activity but i want to use Volley from an IntentService. An intentService destroys itself after the work is done, so the Volley callbacks never retreive the response.
one solution i have found would be to use RequestFuture and call .get() to block the thread. i have an example below that i found here.
Can I do a synchronous request with volley?
RequestFuture<JSONObject> future = RequestFuture.newFuture();
JsonObjectRequest request = new JsonObjectRequest(URL, new JSONObject(), future, future);
requestQueue.add(request);
try {
return future.get(30, TimeUnit.SECONDS);
} catch (InterruptedException e) {
// exception handling
} catch (ExecutionException e) {
// exception handling
} catch (TimeoutException e) {
// exception handling
}
.
I don't want to use JSON as the server returns xml. i've looked at the StringRequest class but i cannot see anything that supports a RequestFuture.
http://griosf.github.io/android-volley/com/android/volley/toolbox/StringRequest.html
Is there anyway to use the StringRequest code to return xml using the blocking functionality of RequestFuture
thanks