I have a done a project in which data like name, url, desc are coming from server using web-service. Every time I need to parse it and then display. I want to use store parsed data in a particular are in which parsed data will be removed after five minutes. Is this possible to do that, if yes then how? I have searched lot and found one thing "mamcache" but not clear how can be used mamcache in Android
Edit
Actually in my app I have different category and clicking on every category, sending request to the server and then parsing it and then displaying. I don't want to send request every time, so I think we should use some technique by which we download data when app runs first time and then store parsed data in a temporary location (this location will store data only for five minutes). I will check often if temporary location has data then fetch from there otherwise send request download, parse and then display.
Your description of what you need is a little vague, but if you need to persist parsed data you can build a model for your data to store it temporarily, or you can save the data to the application preferences which will be available across app instances.
If you can better describe exactly how you want to use the parsed data, I can give you explicit direction?
Edit
If you only need to persist data for a short period of time within the same activity, then use variables to store your parsed data. If the variables are populated, then don't hit the server. If the variables have not been initialized, then hit the server, parse and put the data into the respective variables. As for holding the data for 5 minutes, use a datetime variable to check if the other variable data is stale.
Do you have control over the server? You could implement caching.
See blog post here:
http://android-developers.blogspot.com/2011/09/androids-http-clients.html
HTTP Caching has been back ported here:
http://code.google.com/p/httpclientandroidlib/
You could also implement a cache yourself using DiskLruCache.
Related
I am trying to import some data from server to my android app. Server gets data from sql server and returns it throw a HttpRequest. I parse the data from HttpResponse and store it in sqlite database upon the JSONObject is parsed.
However the number of objects to be inserted is high and the operation may be canceled intentional(by pressing pause) or unintentional(internet problem). So I have below choices:
1- Ignore inserting into database after parsing JSONObject and wait for complete successful response from server: This solution is highly bad because if a problem occurs the user should start importing data again.
2- Make a feedback to server when I insert a row to database. So if I resume importing data just new records are imported from server: It is good but imposes extra network communication and also may affect performance.
3- Get one data packed file and try to parse it: So I am sure pausing the operation will not cause to data lost. But I prefer another solution rather than working with file.
What is the best way to handle this issue?
Thanks
I went through this choice two weeks ago.
I found the better way to manage these data is to build a web service in the server (for example, in PHP; i was using a wordpress blog), send to the web service an offset and limit request and then download the data in JSON format.
In this way, if you have 100 rows to query, you can tell the web service to give you the first 10 results, then you can parse and store them, and then, you can go back with another query asking the results from the row 11 to the row 20, and so on.
In this way, the app will manage many sequential requests (and the related low-weight JSON answers), instead of an extremely big JSON file.
You can also manage all these operation in background or with AsyncTask so, in the meantime, the user can work on the foreground activity.
I have local sqlite storage for my app. Once the user enables online sync option the data syncs with my online server using Asp.Net webservice. For syncing i am concatenating all tables' data in a single string and then passing that string parameter to service.
Example : "table_name1$col1_value$col2_value$col3_value|table_name2$col21_value$col22_value$col23_value.."
Its really hard to manage sync status of each row using this approach. And somehow it doesnt looks like a good approach to me.
The other approach i tried and looks better than this is to pass List of tablename1, List of tablename2 objects in a single containg object or as different parameters.
I am sending data in JSON format.
What approach should i follow to pass the data to webservice(any better approach than these two). A optimal and standardized approach for this.
Best approach is use a time stamp to handle this.
Initial request to server with time stamp value 0.
Server will give the all the data first time with Time-stamp.
Store the Time stamp to sharedpreferences.
In All next request pass the time stamp back to the server
Server will send only those data which are add/update/ after that
given time stamp
That is it.
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)
In my application, I am loading the content for a GridView using a remote JSON file. But that JSON update once in a month. So the user no need to connect Internet every time he/she loads the GridView. So what I have done is, stored the data in to a database for the first time GridView load and next time I'm filling the GridView using the database.
Now I have a problem. I want to send a notification or something like that, when a new item added to the JSON file. With out using C2DM, is there any other way I can achieve my target?
I thought something like a notification that we get when a new version of an application is available. If it is applicable, how can I do that?
If you don't want to push data onto your app the other obvious way is to poll at regular time intervals. A service can do that in the background. Once the server replies positively you can display a notification.
I have found a different approach for the same question. Here we don't need to use either Push Notification or C2DM. By using HttpUrlConnection class and getLastModified() method, we can achieve our target.
Logic is, we save the last updated time of the file in our SharedPreferences and next time we load the app, the SharedPreferences value and the last update date of the value is same, we can load the cache data or the data we have saved in our database. If those values different, then only we download the data from the server.
The application that I have in the works uses GPS data to mark files to a location which the user can then go back and see at the location later on. However I am stuck on how to send my data to the server which I want users to be able to see later.
What I was curious to know from the community here is which is the best way to go about that. I already have the GPS data from the location manager and its associated classes but I'm not to sure how to send that along with an image, sound file, or video in one seamless data transmission to the server where it can be stored in then later retrieved by the device according to the users privileges.
On the server the data is going to be saved in a postgresql data base and I'd like to have it all data associated with each upload tied into a json array of some kind being that I have the app pulling data in json arrays associated with positions and their marks.
So should I send out the GPS data as literal strings that a script on the server can parse into json format and if so is it possible to do that with an image attached to it as well........I know its possible but I guess I just havent figured it out yet.
Or should I use some kind of library or something to bind the image/files to the gps data and send them as data stored in a json array.
I always find sending textual data (like gps values) easiest if done as JSON. If you have to put image/sound files into this as well you can do this by base64 encoding the data and putting the resulting string in the JSON.
Personally I don't like the base64 for 2 reasons:
It adds about 37% to the size of the data
If there is a problem with the connection you have to send everything again, rather than just the files that got messed up.
Another way is to link images/sounds with a UDID. You send the JSON first with the references and then send each file separately to a handler on the server that accepts the UDID as the argument so it knows which file is being received. That way when there is a connection problem you only need to resend a single file.