I have tried the method from Android Volley return value from response but I keep getting this error : com.box.ajian.box.Controllers.IOFunctions cannot be cast to com.box.ajian.box.Constants.VolleyCallback . What should I put in my casting area for it to work? I am quite confused with tis volleycallback stuff.
This is my code. Hope someone can help me
IOFunctions.java (Not an activity)
public void checkIfPersonExists(final Context context, final Person aPerson){
StringRequest postRequest = new StringRequest(Request.Method.POST, USEREXISTS, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d("RESPONSE",response.toString());
((VolleyCallback)context).onSuccess(response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
}){
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String,String> params = new HashMap<>();
params.put("email",aPerson.getEmail());
params.put("phone",aPerson.getPhone());
return params;
}
};
Volley.newRequestQueue(context).add(postRequest);
}
Functions.java (Not an activity)
public Boolean register(Person aPerson,Context context){
ioFunctions.checkIfPersonExists(context,aPerson);
new VolleyCallback(){
@Override
public void onSuccess(String result) {
if(result.equals(false)){
Log.d("HELLO","HELLO");
}
}
};
return false;
}
Register.java (Activity)
functions.register(new Person(Firstname,Lastname,functions.dateFormatter(DateofBirth),Email,Password,Phone),Register.this);
Interface
public interface VolleyCallback {
void onSuccess(String result);
}
The activity register calls the functions.java which then calls iofunctions.java. I want iofunctions.java to return a true or false and so Im relying on volley.