I am building an android application which requires displaying images as a flip-view which will be retrieved from server. I have considered two approaches
Retrieving images from server URL and then displaying OR
Storing the image in db at server(MySQL) and then retrieving it from sq-lite on android application
My question is, which approach will be better considering everything (performance, etc.)?
Any other better approach is also welcome :)
This depends upon your Application and products you are going to display using Images, If they are not updated frequently then it would be better to use caching for faster user experience but if data is regulatory updated and previous data is keep getting filtered then always load using network.
Another approach you can just store latest 10-20 entries in your Database and as soon as you opens the application he can see some data and new data gets downloaded, this approach keeps users engage don't leave them your app just because every time they see loading.
For Image caching purposes there various good libraries avaible which are stable solutions for multiple images downloading as well as caching purposes E.g.
UniversalImageLoader, picasso, Volley
A good approach could be store locally images locally on demand, and keep it on cache, if the image changes on future you can invalidate your cache and download a new image.
I have used in a project a library that helps me a lot with to download the image in background, allows you also load image from cache automatically if stored previously or invalidate the cache. The library is android-query and here is an example of how you could use it.
You store images locally and load then to your app from local storage (This happens in a background thread)
You update the local storage by fetching the images in background, when needed, and then trigger the load from local storage (This also happens in a background thread)
This way you won get ANR's (application not responding) because of slow or missing internet connection, and you will be able to show images without connection at all.
Related
I'm new to caching and stuff. I have an app that fetches images from firebase storage by their url using Glide. Now it will cost me a lot if the user fetches a single image "every time" they use the app using the url (also a single image might be visible in couple of activities , so then fetching becomes redundant). So does glide cache is valid even after app restart and across all the activities or is it activity related( I mean for every activity does it has separate cache or is it just simply dependent on the url)?
Also is the caching enabled by default?
Sorry if the question sounds stupid, but otherwise the cost will increase significantly. Thanks.
Yes it's store some cache after app restart also the best way to invalidate a cache file is to change your identifier when the content changes (url, uri, file path etc) when possible.
My app uses images from a URL and I want to reduce resources usage for both server and client.
I wonder if the Android SDK already offers something for this (if there's some standard way to do it) or I just have to figure it out.
What I have in mind is:
download images on local storage (external or internal) when accessing content (lazy loading, progress bar) and keeping them there for next use
update images (download and replace) if changed on server (keep checksum in a database that is queried when the application is started)
in order to avoid excessive local disk usage (they are quite big), delete images for content that has not been accessed for N days. This is done while loading the app or in a background asynchronous service
Should I do this step by step or is there something that already takes care of it. Are there libraries to do this properly?
I think Picasso library is best for this, it has many capabilities and is really easy to use, its features include smooth image caching (the features you need), image processing and Async downloading from URL too. It has so many useful features.
Here is its url link
http://square.github.io/picasso/
I want to save the images fetched from server for once and from next time i want to check first whether images are stored or not in device, if not then again it should fetch from server and store in user's device again, and if yes then application will use images directly rather than fetching from server again and again. It will be useful for enhancing the speed of application. Basically my application is fetching multiple images from server so i want to save those images on user's android device and from next time application should fetch from device. I think you got my question.
The simple way:
You can use Picasso.
It is a simple lib which provides image downloading and caching.
In my opinion it might not be the fastest, but it is pretty simple and intuitive. It does its job well and none who I asked complained about it.
Picasso
Other libs:
UIL
Volley
Glide
fresco
To make it short. There are lots of other libs. An awesome comparision of the most Populat ones can be found here and here
The do it yourself way:
You can also write you own caching logic with a LRUCache. Which is also pretty simple.
Take a look at:
https://developer.android.com/topic/performance/graphics/cache-bitmap.html
The LRUCache is just a Memory Cache so you might also want to use a DiskLRUCache
My DataBase contains 1000's of images on server , I have to display these images in ListView in Android.
I have to develop similar List like that in the Flipcart app(If User Scroll then download Images) and store a local copy in SQlite and display from that SQlite database.
(In future if connectivity would not be there then also I would be able to run my app)
because Images will be available in SQlite.
Please suggest proper Solution for that.
Use of loaderManager or something else please suggest
I don't advise towards storing the images themselves in the SQLite database. The database will become slower to use and more cumbersome. Also, I think you should not implement such complex functionality yourself as there are many ready to use open source solutions.
There are a lot of solutions that allow you to cache the images on the file storage. They work transparently - when you request url they first check the local cache and only if this check does not exist they will make network call. Most of them also will display default thumbnail until the network call succeeds. Basically I think this is the best you can do.
I, myself have used Universal Image loader for what I describe, but out of this thread you can find many alternatives.
I'm developing a part of an app where application is supposed to read product-images and prices from online storage (website, which is to be built for this purpose only), make local storage of product-images and prices so that it could show the product-images and prices when it is offline. there will be a button; once it is pressed, its job is to synchronize the local cache. How could I implement this ? Any help would be highly appreciated.
Thanks in advance.
You can cache the bitmaps from a remote service using a Disk Cache, there is more information about how to do this on the Google developer site http://developer.android.com/training/displaying-bitmaps/cache-bitmap.html
This will allow you to store the images and display immediately if there is no connection, or you want to load the images whilst loading the remote images.
Depending on what text you need to store you can associate the text with the images in the cache or alternatively set up an ArrayList with the data and store to disk. Some more details here Best Way to Cache Data in Android
Also there are tools around to ensure you are making the most of your network connections, such as the AT&T ARO tool, running this will help you to optimize your app by reducing your network calls to a minimum. See http://developer.att.com/aro