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
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
}
Related
been working on this one about a week already. So i'm using React Native's fetch method to access our API. Using the GET method works, means that i was able to get data in our API. The problem now is the POST and PUT methods, when using PUT to send data, the value passed is always a null value. I tried using console.log in chrome browser, the response is 200, so means its ok and it was able to talk to the API, the only this is that the value is sent is always a null value. Note also that manually updating the data using Postman works, only doesnt work when API is called from React Native. help will really help me continue my development since i'm really stuck with this one. Thanks a lot guys
See this file to see some code snippets
I also had this issue before and what I found out about the problem is:
Our server does not prepare api for "utf-8", and android avd sent requests with "charset=utf-8". So it will cause one of the platform showing error because the request charset is not same.
The issue is here and they still not fix it: https://github.com/facebook/react-native/issues/8237
Check the Content-type in the headers of your POST and PUT requests. Set it to application/json if your API takes parameters in JSON format.
I'm facing a pretty big problem today: I decided to use Parse as a backend for my mobile application. When retrieving data from server, Parse put the result in a local cache so we can use it offline too, which is great. But when adding or updating an object offline, Parse has no mechanism to update the local cache, which leads to big problems when the app has to be used offline.
I decided to maintain a local cache by myself using SQLite : I look on the server entries and on the local cache entries and then, using the dates, I manage to synchronize the data. The problem is that the updatedAt and createdAt fields are set when data are saved in the backend (which is normal), but then how do I know that an entry created offline is older or younger that the online data ? I could use the phone's time but that's quite random knowing that there could be a difference of some minutes.
Any idea?
I'm even open about new tools to use. I mean I'm not focused on Parse so if you have the perfect tool just tell me!
you could set a last synced time in shared preferences and if the updated or created time is > the last sync time then you know it is new then update the last sync time again when your sync is done
How about saveEventually()? Based on the explanation in the API docs, I think this will solve the problem.
Also, one more suggestion, if you want to cache your ParseObject, instead of the painful SQLite and tables and all, you could use internal storage to save the object as is explained in this article.
There is a problem on Class with pointer.
Known bug: https://groups.google.com/forum/#!topic/parse-developers/arRBB7S559M
I've built some pretty straight forward apps earlier using phonegap for android.
Now i'm building one that will need statusbar notifications from a background service per user.
Using phonegaps backgroundservice plugin, im able to get notifications through the example twitter feed.
getMethod = new
HttpGet("http://search.twitter.com/search.json?q=phonegap&rpp=1&page1");
It works as expected, but i'm having big troubles with it.
1 - im not good with json
2 - ive yet to figure out how to store user credentials( user id f.example) on phone.
So lets say i want to build my own json file, myjson.php. in my java class, i cant pass a userid since this is not stored locally, and im unable to fetch it. my httpget would be:
getMethod = new
HttpGet("http://domain.com/myjson.php");
Myjson.php would serve me any new messages, so i have to have a way of specifying which user is requesting the file. Concidering it is all through sql, it has to be the same values.
php sessions wont cut it as phones often clears caches and forgets user credentials.
How can i do this? local sql? xml?
And if i manage to store the user credentials locally, how can i add these to my httpget request?
Any help and pointers are greatly appreciated as ive read and read and read and now = stuck.
You can store data locally using LocalStorage. It's very simple. (Link: https://developer.mozilla.org/en-US/docs/DOM/Storage)
Your first problem is you dont really do json. You just ask for a content encoded in Jason. Look at the native code contained here.
Sync data from the server using json parser
I have developed android application for offline concept.When internet connected more than 4000 records synchronized from the server. If i add only one data in the server. when i do second time synchronizing, that particular data to be synchronize from the server.My problem is when i do second time synchronizing data it took same time as first time synchronizing. how to avoid this,please advice me.
Synchronizing working fine. But if i press the sync button second time. whole data can be synchronizing again. Please explain in detail. I have little bit idea i don't know whether it is correct or not.
My suggestion:
Flag to be set in the server side and client side. If data synchronized flag to be set as 0. if data newly synchronized it should be set as 1.
if data loss. unfortunatly data cache cleared in application. how to do this?. please explain me.
Check this video
Here a googler explain how to build REST applications - there is a lot of usefull thing about sync.
If you build server and client by youw own - you can store timestamp of the last connection and each time you synchronize you pass this time to the server and depend on it you can pass only modified columns (you have to store timeStamp of modification for data or list of modified columns from key timestamps)
I have an app on iphone and android that both fail periodically when calling the server. When I say that they fail I mean that I get no errors codes, 200 Connection code meaning that it was successful, but a corrupted string/data/(jsonObject/Array). I list all of those data types because depending on the app they use some or all of them. The information when printed out in sting form does have the return JSON coming from the server, but it is corrupted with extra code or text that will not allow JSONParsers to work properly. Like I said before it doesn't fail all the time and it only fails in what is in the returned string/json/data. I have been told before that I am connecting, receiving, and handling the information correctly and that I should look to the server. We have changed servers in the middle of this and it works faster but still has a similar fail rate. Also, the server does not fail or have issues with browsers. So, in all web browsers it throws no errors, doesn't corrupt the site and or the information that is displayed. So, if I get on my computer and go to the website I will see the correct information every time when I load the page. Any ideas would be greatly appreciated.
The answer that I found out for android was that it was the old server, but the new serve still had issues with the IOS app but I figured out that if you alloc the NSString with the NSData then the information will not have any possiblities of gaining extra data or information. So alloc works.