0
Hello guys I am developing an android application that uses the library Volley (google) to perform my requests http. I have a method that returns a Boolean and depends on the return of the request, that is the wickedness, the method returns the value before finishing the request.
public class MyService implements IMyService {
private Context context = null;
private Boolean result = false;
public MyService(Context context){
this.context = context; Thread
}
@Override
public Boolean isUrlValida(final String url){
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String s) {
result = true;
Log.w("isUrlValida", "onResponse");
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.w("isUrlValida", "onErrorResponse");
}
}
);
((AppApplication) context).getRequestQueue().add(stringRequest);
((AppApplication) context).getRequestQueue().start();
return result;
}
}
Will I need to perform some Thread’s control ? Thanks !
what return there is?
– Lollipop
200 - ok, it enters onResponse() the problem that already returns false without waiting for the request
– marcossilvajnr
I believe that the way to work with Volley is almost the same when working with Asynctasks, you will have to implement a "wait" for the user until you get the content you need.
– wryel
Add this: if (s == null) { }- TO TEST.
– Lollipop
@wryel I’ll take a look at the Asynctasks.
– marcossilvajnr
@Rafael remains the same, thank you all.
– marcossilvajnr
Debug each line to identify where it enters or not.
– Lollipop