小编Cri*_*m G的帖子

如何从函数onResponse of Retrofit返回值?

我试图返回一个从调用请求中的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方法中使用它我需要声明它最终,我不能给它一个值.

java methods json retrofit

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

令牌认证Android Studio

如果我想将从服务器检索到的令牌存储在我可以从我的代码中的任何位置访问它的地方,以便将其作为json头发送到我的服务器,我应该在哪里存储它?有没有其他建议你可以让我使用令牌身份验证?

security authentication android token

2
推荐指数
1
解决办法
5698
查看次数

标签 统计

android ×1

authentication ×1

java ×1

json ×1

methods ×1

retrofit ×1

security ×1

token ×1