0

With reference to the Question and Answer at - Android Volley + JSONObjectRequest Caching

I am implementing volley and facing issue of the cache (forced caching) at the APP end and am unable to do it.

Answer suggested by oleksandr_yefremov, is to create a method. I am unable to use that method. Can anybody help in understanding and to use is in fetching string from a url and cache it.

Here is the code suggested by 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));
}

}

Please guide me to use it for string fetch and cache.

Thanks

Community
  • 1
  • 1
MSN
  • 566
  • 7
  • 13

1 Answers1

0

in the method parseNetworkResponse you do not have access to Volley cache, so you can not cache your result, what should you do?

at the function onResponse get the Volley cache from your request queue and then change your response to string (because now it is json) and then put it by the key value of your request URL.

mmlooloo
  • 18,937
  • 5
  • 45
  • 64