Android的凌空JsonObjectRequest返回相同的响应移动数据每次 [英] Android Volley JsonObjectRequest returns same response every time on mobile data

查看:355
本文介绍了Android的凌空JsonObjectRequest返回相同的响应移动数据每次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用凌​​空JsonObjectRequest 从服务器获取数据

I am using Volley JsonObjectRequest to get data from server.

code片断:

JsonObjectRequest jsObjRequest = new JsonObjectRequest
        (Request.Method.GET, url, null, new Response.Listener<JSONObject>() {

    @Override
    public void onResponse(JSONObject response) {
        System.out.println("Response: " + response.toString());
    }
}, new Response.ErrorListener() {

    @Override
    public void onErrorResponse(VolleyError error) {
        // TODO Auto-generated method stub

    }
});

但我收到同样的的JSONObject响应移动数据连接的每一次。

But I am getting same JSONObject response every time on mobile data connection.

注意:这是完全的WiFi连接工作。

Note: It's work perfectly on WiFi connection.

有没有人面对这个问题?任何解决方案?

Is anyone facing this issue ? any solution ?

推荐答案

@BNK request.setShouldCache(假); 为我工作。这是凌空缓存管理的问题。

@BNK request.setShouldCache(false); worked for me. It's issue of volley cache management.

我认为,当一个请求被发送:

I assume that, when a request is sent:


  • 这将先打缓存和发送到 onResponse

那么当结果从远程服务器通过它来将其提供给 onResponse

then when the results come through from the remote server it would provide it to the onResponse

如果你使用任何凌空实现的默认请求类(如StringRequest,JsonRequest等),然后调用 setShouldCache(假)右键添加请求对象之前到凌空请求队列

If you use any of the default Request classes implemented in volley(e.g. StringRequest, JsonRequest, etc.), then call setShouldCache(false) right before adding the request object to the volley RequestQueue

request.setShouldCache(false);
myQueue.add(request);

您还可以将过期策略作为缓存。

You can also set expiration policy for cache.

看到这个答案更多细节

这篇关于Android的凌空JsonObjectRequest返回相同的响应移动数据每次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆