I am new with retrofit, i have a function with Async Retrofit, with purpose like this example
public boolean bookmark(){
boolean result = false;
Call<Response> call = service.bookmark(token, request);
call.enqueue(new Callback<Response>() {
@Override
public void onResponse(Call<Response> call, retrofit2.Response<Response> response) {
result = true;
}
@Override
public void onFailure(Call<Response call, Throwable t) {
}
});
return result;
}
but i dont know how to return that value.
You can use a custom interface. If you pass the interface as parameter to the method "bookmark", you can use it.
try something like:
public interface BookmarkCallback{
void onSuccess(boolean value);
void onError();
}
your method should look like:
public void bookmark(final BookmarkCallback callback){
Call<Response> call = service.bookmark(token, request);
call.enqueue(new Callback<Response>() {
@Override
public void onResponse(Call<Response> call, retrofit2.Response<Response> response) {
callback.onSuccess(true);
}
@Override
public void onFailure(Call<Response call, Throwable t) {
callback.onError();
}
});
When you call this method, you have to pass one callback instance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With