I'm trying to do implement login using a ASP.Net Web Api into an Android application.
What I have so far are functions that work, just that I want to make the login request kind of synchronous instead of asynchronous.
I'm using Android Asynchronous Http Client like they say on their website.
public class ApiInterface {
public static final String ApiURL = "http://******/api/";
private static AsyncHttpClient client = new AsyncHttpClient();
public static void get4Login(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
client.get(getAbsoluteUrl(url), params, responseHandler);
}
private static String getAbsoluteUrl(String relativeUrl) {
return ApiURL + relativeUrl;
}
}
And I have this function in LoginActivity:
private boolean doLogIn(String user, String pass) {
boolean result = false;
if (user.trim().isEmpty() || pass.trim().isEmpty()) {
return false;
}
RequestParams params = new RequestParams();
params.add("user", user);
params.add("pass", pass);
ApiInterface.get4Login("Auth", params, new TextHttpResponseHandler() {
@Override
public void onFailure(int statusCode, Header[] headers, String responseString, Throwable error) {
Toast.makeText(MyApp.getContext(), "Error: " + error.getMessage(), Toast.LENGTH_LONG).show();
}
@Override
public void onSuccess(int statusCode, Header[] headers, String responseString) {
//***Here I want to set the doLogIn() function result depending on the response from the server;***
Toast.makeText(MyApp.getContext(), "Lista sesizari incarcata!", Toast.LENGTH_LONG).show();
}
});
return result;
}
Is there any way to do this?