【问题标题】:Volley forced cache - how to achieve it for caching string from a url?Volley 强制缓存 - 如何从 url 缓存字符串?
【发布时间】:2014-09-25 16:47:43
【问题描述】:

参考问题和答案 - Android Volley + JSONObjectRequest Caching

我正在实施 volley,并在 APP 端面临缓存(强制缓存)问题,我无法做到。

oleksandr_yefremov 建议的答案是创建一个方法。我无法使用该方法。任何人都可以帮助理解和使用从 url 获取字符串并缓存它。

这是 oleksandr_yefremov 建议的代码

public class MyRequest extends com.android.volley.Request<MyResponse> {
...

@Override
protected Response<MyResponse> parseNetworkResponse(NetworkResponse response) {
    String jsonString = new String(response.data);
    MyResponse MyResponse = gson.fromJson(jsonString, MyResponse.class);
    return Response.success(MyResponse, HttpHeaderParser.parseIgnoreCacheHeaders(response));
}

}

请指导我使用它来获取和缓存字符串。

谢谢

【问题讨论】:

    标签: android caching android-volley


    【解决方案1】:

    parseNetworkResponse方法中你没有Volley cache的访问权限,所以你不能缓存你的结果,你该怎么办?

    在函数onResponse 处从request queue 中获取Volley cache,然后将response 更改为string(因为现在它是json),然后将其放在请求的键值@987654328 @。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-25
      • 1970-01-01
      • 2012-07-11
      • 2013-05-22
      • 2013-10-24
      • 2014-03-17
      • 2020-10-08
      相关资源
      最近更新 更多