【发布时间】:2016-09-12 16:13:08
【问题描述】:
我在 Android 中使用 POJO 和 Retrofit2 来调用 REST 服务来获取一些数据。我确实收到了 response.body() 中的数据,但我不希望将这些数据分配给任何 android UI 组件。我想获取这个返回的对象并返回或在 onResponse 之外工作。
对不起,我是 JAVA 或回调的新手,但在搜索时发现我需要编写回调但不知道如何编写。有人可以帮忙吗。
代码如下:
public String getUserIPCountry(Context context){
ipf = new Ipinfo();
IpinfoAPI.Factory.getInstance().getCountryCode().enqueue(new Callback<Ipinfo>() {
@Override
public void onResponse(Call<Ipinfo> call, Response<Ipinfo> response) {
if(response.isSuccessful()){
//Want to return/use below data outside of this method
//response.body().getCountryCode();
}
}
@Override
public void onFailure(Call<Ipinfo> call, Throwable t) {
}
});
return null;
}
【问题讨论】:
标签: java android retrofit pojo retrofit2