我试图返回一个从调用请求中的onResponse
方法获得的值,retrofit
有没有办法可以从覆盖的方法中获取该值?这是我的代码:
public JSONArray RequestGR(LatLng start, LatLng end)
{
final JSONArray jsonArray_GR;
EndpointInterface loginService = ServiceAuthGenerator.createService(EndpointInterface.class);
Call<GR> call = loginService.getroutedriver();
call.enqueue(new Callback<GR>() {
@Override
public void onResponse(Response<GR> response , Retrofit retrofit)
{
jsonArray_GR = response.body().getRoutes();
//i need to return this jsonArray_GR in my RequestGR method
}
@Override
public void onFailure(Throwable t) {
}
});
return jsonArray_GR;
}
Run Code Online (Sandbox Code Playgroud)
我无法得到价值,jsonArray_GR
因为能够在onResponse
方法中使用它我需要声明它最终,我不能给它一个值.
如果我想将从服务器检索到的令牌存储在我可以从我的代码中的任何位置访问它的地方,以便将其作为json头发送到我的服务器,我应该在哪里存储它?有没有其他建议你可以让我使用令牌身份验证?