Get Android Asynchttpclient Response After It Finish
hello i am using AsyncHttpClient to send request to restful api the problem is i want to have the result in onSuccess and pass it from the class who have this method to my activit
Solution 1:
I tried to make the method send void and make a callback inside onSuccess
The method being void is good.
Making a callback inside onSuccess can look like this
Add a callback interface
publicinterfaceCallback<T> {
voidonResponse(T response);
}
Use it as a parameter and make the method void
publicvoid send(
JSONObject parameters,
String email,
String password,
final Callback<Integer> callback) // Add this
Then, inside the onSuccess
method, when you get the result do
if (callback != null) {
callback.onResponse(statusCode);
}
Outside that method, where you call send
, create anonymous callback class
webServer.send(json, "email", "password", new Callback<Integer>() {
publicvoid onResponse(Integer response) {
// do something
}
});
Post a Comment for "Get Android Asynchttpclient Response After It Finish"