我是改造的新手,我有Async Retrofit的功能,目的就像这个例子
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;
}
Run Code Online (Sandbox Code Playgroud)
但我不知道如何返回这个价值.
我是改装的新手,我想让我的getData方法返回一个功能对象.最简单的方法是什么?
DataService.java
public class DataService {
private static final String TAG = MainActivity.class.getSimpleName();
private final ApiClient apiClient;
public DataService() {
apiClient = new ApiClientFactory().createApiClient();
}
public List<Feature> getData(){
apiClient.getData().enqueue(new Callback<DataResponse>() {
@Override
public void onResponse(Call<DataResponse> call, Response<DataResponse> response) {
List<Feature> features = response.body().getFeatures();
Log.d(TAG, "Data successfully downloaded");
}
@Override
public void onFailure(Call<DataResponse> call, Throwable t) {
Log.e(TAG, t.toString());
}
});
//I need to return features in getData method
}
}
Run Code Online (Sandbox Code Playgroud)