I am trying to implement a login feature for my android app, where I send an email and a password to the server. In the response I get some values which I then need to continue the app.
The problem is that I want to implement the request in a "requests class" like this:
public class MyRequests {
public void loginToServer(String email, String password, Context context, Runnable myRunnable) {
RequestQueue queue = Volley.newRequestQueue(context);
StringRequest request = new StringRequest(
Request.Method.POST,
myURL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
myRunnable.run();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast t = Toast.makeText(context, "Error!", Toast.LENGTH_LONG);
t.show();
}
}
); // Theres also some post-params and authentication here
}
}
public class mainActivity extends AppCompatActiviy {
Runnable myRunnable = new Runnable() {
@Override
public void run() {
// continue to a new activity + do some database stuff
}
}
MyRequests.loginToServer(email, password, this, myRunnable);
}
I can not figure out how to pass parameters back to my runnable so that I know for example, whether or not the call was successful, etc.
Any good ideas or good practices that I can use here?
Thanks.