androidjsonapihttpxively

Pulling data from web server on android not updating


Im not quite sure whether the problem is with my android program or its a some kind of limitation in the web server api. Im using futurerequest to get the data from xively with api key and feed id, and parsing the data in json format, then storing it in my db. The connection establishes just fine and im able to connect and get the data from the server. This is done through an asynctask and the request frequency is 1 min.

The issue im facing is that when i update the data in the server through web browser, the response on my program is not updated. It keeps getting the old data. When debugging i can clearly see that everything is working as intended, and i can see that the json response object i get from the server is working, however, the data is not fresh. I found out that by changing the api key manually makes the program get the newest data. Also by clearing the cache and data results in fetching the new data from the server. As you you know, i cant ask the user to clear his cache and data everytime to get the latest update.

How do i go about this issue? What might be the reason behind this problem? Thanks in advance!

Edit: Clearing the cache alone does not help. Also, using the phone instead of the emulator doesnt help either.

Im using volley library to handle the request/network traffic


Solution

  • Wanted to updated the solution that i found. This link helped me find the solution. Apparently, there is some caching involved by volley. By using the method

    request.setShouldCache(false);
    

    i was able to get the lasted updates from the server at all times.

    However, when i tried to get the cache with the code below, before setting it to false, to see whats in the cache it was empty. entry would always be null. if someone know why and could explain i would be grateful :)

    Entry entry = queue.getCache().get(url);
    if(entry!=null){
         String data = new String(entry.data, "UTF-8");
         // process data
    }