相关疑难解决方法(0)

如何使用Async Retrofit 2.0返回值

我是改造的新手,我有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)

但我不知道如何返回这个价值.

android asynchronous retrofit2

7
推荐指数
1
解决办法
6814
查看次数

如何从Retrofit onResponse返回方法中的数据?

我是改装的新手,我想让我的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)

java android retrofit2

6
推荐指数
1
解决办法
7155
查看次数

标签 统计

android ×2

retrofit2 ×2

asynchronous ×1

java ×1