Ich benutze volley in der Android-Aktivität, und eine Anfrage machen und bekam die Antwort, aber ich möchte die Antwort vielleicht in einer anderen Methode behandeln, aber es wird nicht funktionieren, was soll ich tun ?Wie die Antwort von Volley in Android
public class TestActivity extends Activity {
RequestQueue queue;
private String result;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String url = "www.google.com/something/I/need";
queue = Volley.newRequestQueue(this);
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
// Do something with the response
Log.i("resp", response);
// I want to do sth with the response out of here
// maybe like this, let result = response
// and see the log at the end of the code
// but it failed, what should I do?
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// Handle error
Log.e("error", error.toString());
}
});
queue.add(stringRequest);
Log.e("result", result);
}