Caching Images? - android

I am developing a Food Recommendation Engine. We have a lot of photos which has to be downloaded from the server during the usage of the Application.
Do we need to cache or store the images locally just to reduce the network activity ?

If the data from the server is not going to change then you should store them but if the data is changed then you can do two things
On the server keep a last updated data date and depending on that always fetch that date from server, check if the last updated data is not obsolete if yes then fetch again or there is no need
Second approach is Store as cache and fetch every time you start your app

Related

search through web-service with json

In my android application im using web-service to get information about food the problem that if i write appl instead of apple,row,skin it dosent fill automatically and an error message will be shown,, what i did i stored 2000 name from web service in sqlite and search through them is it wrong to do this ? and how can i search with misspelling in web-service without the error message ?
The api url http://api.nal.usda.gov/ndb/search/?format=json&q=apple&sort=n&max=25&offset=0&api_key=DEMO_KEY
Salam Enas,
If the data do change frequently (like a movies list) then it's not ok to store it in the sqlite and it's better to be stored in the server database.
If the data does not change frequently, then it's ok to store them on the sqlite database although the app size will increase by 2 Mb which is a drawback.
You may also want to consider other APIs if you are not committed to use this one.
When storing data on the server, HTTP requests burden can be alleviated by caching data on the mobile.
good luck :)

Android - online offline synchronization of large SQLite database

I am developing an Android application to collect the store (Grocery) information.
The application have modules to create store, set it's attributes like address, lat lng, operating hours, manager details, building photos, etc.
Once the store is created user need to list down the assests of that store by clicking photos and providing it's details.
To store all this details, i have around 15 SQLite tables.
Now i want to implement feature of 'Synchronization', all this captured details need to send to server whenever connection is available otherwise detail should be stored locally and whenever connection is available it should move to server.
Also, please note that the number of tables may increase up to 40 as application grows.
I searched for the solutions/approaches for this on Google but in most of the article or example they have mentioned for small scale application having small data.
I have also implemented synchronization feature for small datatable (2 tables), where i checked for last updated timestamp on server and local and if it's different then we synchronize the data. I don't this i should use this approach for such large scale and large database.
I have one approach which doesn't depend on numbe of tables.
I am planning to have single table which store the following data
id
URL
request header
request body
Now let's say connection isn't available while sending request so it will be stored in table. Whenever connection is available it start reading the table and execute the request, on success it will remove the entry from table. With this approach we need only one table in SQLite.
The problem with this approach is when we want to retrieve data offline how we can do that? Do we need to have local database schema same as server?
Please guide.
Thanks
If you are syncing data with a server and you are removing local storage data ,which is incorrect as per my knowledge ,in this case your app does not work offline.So for that when you sync data to a server at that time maintain some flag which data is synced.And then next time just check flag status if it's synced then do not synced data otherwise do syncing.
I hope this solves your problem.

should I save user information in local database

I newbie to android programming and I have question which might sound silly.
I am writing app for a shopping store, which communicate with store's website
Every user must sign in to use the app.
In sign-in process, I save information like user name, address to send products and phone number in website's database.
I have 2 questions:
should I also save user information in local database(sqlite), so in case user would like to change stuff, I won't need to fetch it from web server?(or fetching it every time is better approach??)
The app, display list(picture+description) of products the user can buy(total 12 products).
the list can change every 2 weeks or month. should I save the images locally and have an AsyncTask to check if something changed and only then to download the delta, or should I download them every time.
Thanks in advance
Android provides support for user accounts so it's hard to say whether you can use that or whether you need to implement a custom solution without more details. Have a look here for some information on implementing authentication accounts
As for question 2, I would store the images locally as you say there are only 12. You could then have the server notify the mobile app (check out GCM) when there is an image update to pull from the server. You can also have a look at the Volley library which will assist you in retrieving and displaying images from a web server.
you can store any information in sqlite and use some cache(private/public) to store images for first time store images in cache and from second time onwards load images from that cache use volley library for server calls and image cache
http://developer.android.com/training/volley/index.html
for question two: no you don't need to save the pictures locally to keep your app using the minimum storage space.

Android get data if data is one hour old from the Web Services

I have the android application where the webservices data is not frequently updated say once in a day.
I have to save data in DB for offline viewing as well, right now I am thinking that, when user clicks an button to get data it checks if the last data entered in DB is one hour old, if no then no downloading from web service if yes then download.
So, at the time I am saving data I will save current time with it , and calculate the difference and get latest data.
Is this a correct approach.
Asmi
Having a field in database table just for this purpose isn't an ideal approach. Instead, you should save the current time in SharedPreferences and compare the time to see if data needs to be refreshed.

Store data for few minutes for further access

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.

Categories

Resources