Can Universal Image Loader use different DiskCache for images? - android

I'm using Universal Image Loader for image loading, In the document I can't find a way to set different DiskCache for image display, the DiskCache directory is set by ImageLoader.getInstance().init(), which is global.
But I want to store some images in a separate DiskCache because I don't want it to be removed when LruDiskCache is full or cleared manually, I there anyway to do this?

I am afraid UIL can't store specific image files intently. If I guess right, these images that you want to store in separate directory are used frequently. But, maybe you don't understand the mechanism of LruDiskCache which means "least recently used disk cache". Which means files used frequently would at the header of the queue all the time. So, if you use LruDiskCache, these images used frequently will be always stored in the disk and not be deleted or cleared. So, your requirement has been fulfilled when you use LruDiskCache.

Related

Best practices for photo storage

I want to make an Android application that has the same look as Instagram, which means every profile has a gallery of photos.
My question is about storing and retrieve those photos. I want to know what is the best practice for photo storage in a database (MySQL), more precisely:
Should I store photos with original size (2mb for example) or resize them with smaller size?
Should I store them with two version (smaller size photo, and normal size photo)?
Saving images in the database looks like overkill, it's not needed. Saving on disk should be fine.
Although you should focus on your business logic & leave this to image libraries which does this stuff & do best for memory & performance.
Some famous libs are:
Picasso
Glide
Universal image loader
Fresco
& you will find many more
Almost each library does lots of stuff for you, such as:
In memory cache(LRU Cache) - so that UI thread is not blocked from doing I/O
operation from disks
Disk Cache - To keep images saved for further
app sessions, also when memory cache reaches its limit its have to be
evicted from it., you can specify disk cache size.
Various image scaling strategies
Image transformations
Clearing up bitmaps for freeing up memory
Network operations on background threads
Background threads management & so on..
My suggestion is to go with one of the image library
I dont think the best practice is to store the photos in a database.
In the DB you store the link/location of the photos example a url to a photo.
About smaller size photo it depends on what you are trying to accomplish because now you need more space to pay for and maybe less bandwidth because you can put thumbnails and let it only load the original size when a user clicks on it. So it all depends what and how you want to archieve
Best practice for storing images is to simply cache them as files and not save them in a database. You could save them as blobs in an sql db but they should be less than 32px by 32px to make things smooth. Everything else should be saved as files. Let me give you an example of WhatsApp.
WhatApp caches most of it's images as files and only saves the pixelated thumbnail in a database.

In Glide 3.x, Is it possible to use different cache directories for different images?

My overall object is to delete certain type of images (which are temporary) after a certain period like after one month, from disk cache of the my app.
I'm using Glide, so I know that using Glide, I can clear entire disk Cache but my goal is to clear only a certain type of images from disk cache. Like for example, live banner images from my app (which keeps changing after certain period). Problem is, they keeps adding space even though one gets inactive. So ideally I should delete all old banner images from cache.
What I'm thinking is have a separate Glide Module just for these banner images and setup a different internal cache directory for these images, and after a month, ask Glide to delete/clear this directory.
Another thing is to use Glide's signature concept which invalidates the images.
For both of above ideas, my problem and question is that I want to use only for certain type of images but more I read about them, it feels like once I use them, they apply to all images being download using Glide
Even if I use multiple Glide module, they all gets used for all the images (that's why there is a concept of conflict management for glide modules)
I might be wrong, and there might be indeed a way to get a solution to my problem. All I need is your help if you know a way :)
I'm aware that if nothing works out for my solution, then to keep my app's size impact low, I'll have to decreased overall internal disk cache size which is 250MB by default.
Thanks.

Preferred way to fetch/show images on Android?

Lets consider the following, I have an app with several dozen photos I want to show the user at any given time.
Right now I'm creating multiple files for each image, sizing them for different screen sizes and storing them in their respective drawable folders.
It's increasing the size of my app dramatically.
So here is my question: Is it possible to store the images on a server and use an image library like Picasso, Fresco or something else (open to anything) to fetch that image and scale it down for the device it's running on without risking running out of memory?
I'm worried that fetching a large image, loading it into memory and then resizing it will cause the same problem as trying to display it on older devices with little memory available to them.
You can write methods to request different images sizes from your server based on client info. Just write a method to measure the screen size and then request the appropriate image based on a URL endpoint (like http://myimageserver.com/images/ldpi/image1.png).
You can do optimization post-download, such as scaling, before saving the image to a local file store.
Using a reputable image loading library is a valid method (my own favourite is Glide).
The answer to your question really depends on the number of images you want to show! If there are lots, then yes storing them on a server is probably best, but also the most time-consuming and expensive (both in time and money).
Your other (easier) option is to keep the originals in the assets folder, and use your image loader to scale and load them for you. The correct path for an image in your assets folder is file:///android_asset/your_image_here.jpg. This way, you're only keeping one version of each photo in your apk and they'll load much faster.

Idea to download images in android

I'm making an android app, here the images are getting from Cloud, is it good idea to download images and save it & use it further. Or download images every-time user uses the app, what idea you prefer is the best?
Because downloading images always is slow & its bad i know but at some point if the images are updated then how to get to know about it?
You should definitely cache your downloaded files!
Do it in your internal app directory where only you do have access to (or otherwise external storage, thats still ok).
Bandwidth and connections are always expensive and should kept low as much as possible.
So your user can see images fast even on a bad connection and your app doesn't waste his valuable bandwidth of a users data plan.
Maybe this could also help you:
https://github.com/novoda/ImageLoader
http://www.androidhive.info/2012/07/android-loading-image-from-url-http/
Make it easy on yourself and use something like Android Smart Image View. It takes care of loading and caching, and it's just about a drop-in replacement for Android's ImageView. Universal Image Loader is another alternative, more configurable, but not as quick to implement.
I used https://github.com/nostra13/Android-Universal-Image-Loader
but I think you not want only download and cache.
these no trick ,if you want check weather the image update or not, you can add metadata for image, just like md5 .
in html and browser, you can set expires header for a image:
enter link description here
but in android app, you control all yourself.
Downloading images and saving them is probably the best way to do it because you don't want to download the same images over and over. If the images are updated you can delete the older one and download the new ones. Just make sure you don't download/save a million images. Take a look at this library. It has a built-in cache on sdcard/external sd.
Downloading images from the net for display, with possible requirement of caching is a very common problem that many people have solved, you can try these solutions to see which fits you:
Ion (https://github.com/koush/ion) - very flexible and feature complete, plus it can download more than images but JSON, Strings, Files, and Java types as well. The part that I really like about this is that it can automatically cancel operations when the calling Activity finishes, so users don't waste time & bandwidth downloading images that will no longer be displayed
Universal Image Loader (https://github.com/nostra13/Android-Universal-Image-Loader) - equally capable for most use cases but for downloading/caching images only

Universal Image Loader enable/disable disc cache for each image

In my android app, I am using Universal Image Loader to display images.
I specified in the option to caching images on Disc. But sometimes there are images that I do not want to cache on the disc. Is there a way to specify if it should cache on disc or not for each time I download an image and not only in the initialization?
Thanks
I just created 2 options one with caching and one without and used each one accordingly.
Will leave it here in case.

Categories

Resources