다음 코드는 전화를 걸고 xml을받는 코드입니다.StringRequest 및 RequestFuture를 사용하여 통화 방해 방지 통화를 수행하는 발리
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);
.
내가 가진 문제는이 작업에서 호출 할 때 잘 작동하지만 IntentService에서 Volley를 사용하려고합니다. intentService는 작업이 완료된 후에 자체를 파괴하므로 Volley 콜백은 결코 응답을 검색하지 않습니다.
내가 찾은 한 가지 해결책은 RequestFuture를 사용하고 스레드를 차단하는 .get()을 호출하는 것입니다. 여기에 내가 찾은 예가 있습니다.
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
}
Can I do a synchronous request with volley?
.xml을 반환하는 서버로 JSON을 사용하고 싶지 않습니다. 나는 StringRequest 클래스를 살펴 봤지만 RequestFuture를 지원하는 것은 아무것도 볼 수 없다.
http://griosf.github.io/android-volley/com/android/volley/toolbox/StringRequest.html
는 RequestFuture감사
안녕하세요, 제가 원하는 것은 무엇인가요? Android가 Volley를 채택했으며 IntentService에서 사용할 수 없다는 이상한 것처럼 보입니다. Retrofit을 살펴볼 것이지만 Volley와 함께 모든 가능성을 다 써 버리고 싶습니다. – turtleboy