I am currently working in a project where I have to get huge number of images from Json(back end) and i have to display it to the user . There is no problem for this process if I do it online (with internet connectivity)
My question is, I have to display the same images even offline too, I know that Glide and Picasso can be used in this but I do not know the size of the cache that both have
Which one should i use now in order to make a good gallery in my application
the thing is, i will get lot of images from back end and i have to display it offline the first time when i sync i will have internet and i will store all the image URL in the local storage
Please guide me how to do this and tell me if there is any other way to perform this
Thank you
Related
I'm developing an android app using Firebase back-end. Everything works fine, I have no problem whatsoever. The only problem is that, the data loading speed. Because it's a cloud-based system, sometimes it takes 4-5 (or even longer) seconds to load a user profile picture or simply to pull username from the database to display user. Now, you might say, well we don't even know how your data structure is stored in the no-SQL table but really I can't go wrong with that. I just structured it in a way that it's just a simple one read query. Or is it normal? Maybe Firebase loads data with some delay.
How you as other developers, get over this loading time? For example, I have a user picture, where the pic should be loaded from the Firebase database, but till pic is loaded, the image-view is just staying as a black view.
All of this depends on several factors that you can check.
Internet speed
Programming type
The size of the files (you probably need a lot of time to load for a
high volume file)
And another solution is to store the information you've previously received into the phone's memory(cache).
I am developing an android application in which when a user logins through facebook his profile picture gets stored. Then the user is shown the profile pictures of his fb friends who have installed the app, one by one. First, one friend's pic is shown then on click of next button, next friend's pic is shown. This continues till all the friends images have been shown to the user or user has skipped the section.
First, I thought of storing all the images in my database and then retrieve them one by one as the user presses the next button. But doing so will render very slow performance as for every time an image has to be shown to the user I have to hit the db.
The alternative is to store images in my local drive and store every image's location in the db.
Please elaborate on how this could be achieved and the performance issues in this case considering a large user base?
Also suggest any other way of achieving the aim, if you may.
I am using WAMP for the purpose.
Thanks in advance.
The pictures are stored in the apps cache after they are downloaded.
When the user logs in to fb for the 1st time it will download the images.
2nd time it will get them from cache unless its a new image.
clear the cache when it gets to a certain MB limit and keep it small
I suggest using Google Volley library to get images from the net as when setup properly you can expire / clear images from the cache.
The are are other libraries for image loading and handling to consider such as Universal Image loader and Picasso but Volley can also be used for fetching Data from the Net.
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.
I am developing Android app now where I need to store image Url in DB for each object and then load this image from the web (if connection is on) OR get it form cache (if not).
Picasso seems to be best lib for handling images in Android, so I starter using it. But I can not get how do I use it properly for my case. Even more - Images strangely are loaded into views right after they are first time get from API but if user starts app again, we can see placeholder only (even with internet connection on). Can someone suggest a solution or at least any kind of idea of best way to do this?
My code in Adapter (is is also same in ShowActivity):
String img_url = item.getImage(); // img_url is valid image url
Picasso.with(mContext).load(img_url).placeholder(R.drawable.plchldr).fit().centerCrop().into(holder.image);
I tried to use Picasso at the start as well, and found out that their caching system is horrible.
It would cache some images i downloaded, but not others, and would therefore leave alot of images with placeholders.
I suggest you try Universal-Image-Loader (https://github.com/nostra13/Android-Universal-Image-Loader). I'm currently using this to cache all images in my app, and it works flawlessly (Around 200 images atm).
Finally got the problem - API is returning valid image url BUT actually it (image) is hosted on S3 cloud and it is expiring till the user loads application again. So, actually saving expiring image URL is useless in this situation. I am not sure what will I do here (it seems that the only way here is hard one - storing images on SD as Bitmap). But I just wanted to tell this for those who will get similar issue.
I am building the application that will load list of news from the website. Each news/headline has an image. I want to save/cash the images so user does not has to download them again.
Q: In your opinion, what would be a better/more sufficient way: Loading images and saving them on the device or use the CacheManager? At the moment I am using the first solution and everything works fine. However, the website has many categories and even more news per category therefore there are lot of images saved on the device. Is it normal in this type of applications to save the images on the device?
Thanks for your help,
marqs
I don't think you should save the images on the device, because of many reasons:
Why wasting the device space on news images? All the user wants is to read the news and thats it. (In your case maybe open it later, but still - not forever)
You can save it on the device and make the app. delete those files after lets say 24 hours..
The main issue is the privacy issue, when the user is deleting the cache files he thinks all the webs he visited has wiped from the device, but in this case they aren't..
Maybe you can just add a "Clean Cache" button in the app. but after all I wrote I think using the Cache-manager is the best way - just because it was meant for those things exactly..
:)
Rotem
I didn't find a reason to use CacheManager. I used getCacheDir and stored everything on file. I have two levels of cache. First when I fetch it, I store in memory and disk. When in memory gets bigger than 30 objects, I started clearing the memory to make some room for the new images coming. However, I still keep the images around on disk and bring in to memory as needed. I found this to give me the smoothest scrolling. After about an hour, I start expiring the image on disk too.