如何从谷歌凌空获得回复?我可以使用System.out.println(“Volley”+ response)在我的logcat中显示响应;
我无法弄清楚如何将其从谷歌排球功能中拉出来。继承我的代码:
final String url = MAIN_URL;
// prepare the Request
StringRequest sr = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
System.out.println("Volley"+response);
//I want to be able to get this response and use it in other functions.
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
System.out.println("Error"+error);
}
});
// add it to the RequestQueue
sr.setRetryPolicy(new DefaultRetryPolicy(
10000,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
queue.add(sr);
答案 0 :(得分:0)
我总是将队列放入单例中 - 可以在代码中调用和接收应用程序和请求,例如:
android volley caching asynchronous requests - How te get url of the request in ResponseListener
所以你只需在你需要的类中创建自己的响应监听器