【发布时间】:2017-07-26 22:47:48
【问题描述】:
我是改造新手,我想让我的 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
}
}
【问题讨论】:
-
你的问题已经在stackoverflow.com/questions/34184088/…得到解答
-
call.execute().body()
-
@uguboz 并阻止 UI 线程?没有。
-
@uguboz 不需要额外的库。我的回答应该没问题