Loading images from the server is very slow - android

I am trying to load images from the server and want to know how can i convert the images into the thumbnails so that they get uploaded fast and how can i get the larger images from the thumbnails fast . I have tried many things.
Thanks in advance

At the server you need to keep 2 copies of an image. First is the thumbnail and the other one is the image.
First you need to download the thumbnail asynchronously. And if the user wishes to see it then download the original image asynchronously. While downloading original image you can show the scaled thumbnail image as the placeholder image. So when the downloading is completed show the downloaded image.
Make sure to download the images asynchronously otherwise you will block the main thread and UI will get stuck.
This is how google images work.
In iOS there is a very nice API SWPhotoBrowser which handles the downloading and caching of photos from the web seamlessly. I am sure there must be some API for Android as well.
If you need any help I can help with the code as well.
For Android you can use ImageLoader to download and display image - it can use cache and save memory while loading scaled images.

Related

Getting large number of images in recyclerView android

in my recent android project I have to get a large number of images from the web and show them in my main activity (something like explore part of the Instagram app). I used a recyclerView with gridLayoutManager of 3 columns and I have to get something like 700 images from URL. When I open the app and comment the getting image part, app work perfectly fine (the app get the information of each tile but doesn't display the images). But when I start setting image bitmaps the app start becoming laggy and crash after about a hundred images loaded.
What do you recommend me to do ?
And another question: Was using recyclerView a smart idea ?
Thanks for your reply.
Don't load hundreds of images. That requires a few things:
1)Don't store images in memory in the adapter. Store the url/resourceid/whatever of the image so you can load it on demand.
2)Use an LRU cache of images, limited in size and load your images through that.
3)Make sure that however you download images does not spawn too many concurrent requests, and that requests are canceled when no longer needed (when the view it would go into is recycled).
4)I'd suggest downloading the images and writing them to disk, then loading them from disk as needed. This will prevent you from having to keep the entire file in memory to decode it while downloading it, which will reduce your memory usage while downloading.
5)Do not decode the image on the UI thread. Do it on another thread.
6)If you don't need to display images fullsize, make thumbnails.
Images in a RecyclerView, especially if being downloaded need a lot of work to do well and handle rapid scrolling.
You should post some code here but seems you are asking for some efficient setup.
First of all, try using some image caching libraries like Glide or
Picasso. It manages and caches your images locally so you don't end up
making multiple requests for the same image.
This solves most of your problem and don't try to load 700 images
altogether and display use lazy loading means load first 10-20 images
first and when user scrolls make another API call for another 10-20
and so on.
Here is an article on how to use Glide and how it works.
https://futurestud.io/tutorials/glide-image-resizing-scaling

Image loading with JSON service

I have an app where people can set pictures as wallpaper but its really slow because pictures are very big. This app load pictures and then when i want to see it again it has to load again.
What to do to make it faster? I use Json service. My pictures are from server. i am using universal image loader.
Theres 2 types of cache in android, the memory cache and the disk cache. You should use picasso its a library that implement both and is very easy to use (1 line of code).

How ca I use an Image for entire application without downloading again

In my Android application I have to fetch some images from the server and show them.Same image is shown in some of the pages.Now I am downloading the same image in each page and getting out of memory error.How can I reuse the one that I have downloaded earlier in each page
Use Android Query, and then Image Loading in particular. It's really easy and performs well.

The Best Way To Load Multiple Large Image in a GridView

My Problem deals with Memory, I have a Web service that provide me a List of Urls. Each URL corresponds to a large image. My Mobile app have to parse the xml provided by the web service and than show in a GridView these images. I tried several features in order to display images such as:
Multithreading
Lazy Loading
Reduce image size using inSampleSize ( this causes my app takes too long)
should i have to attach for each large image a thumbnail image, and make the web service return to me the list of all thumbnails, after that show these thumbnail to the user, and if he clicks on one of them than i have to show the large image in a separate view, i have this idea because i noticed when i show one image i don't get an outofMemory exception!!
Is this a reliable solution? is there a better way?
Welcome to one of the hardest issues on Android. First I would start by reading this new documentation google wrote on how to handle bitmaps. Its not a light read, but you probably need to read it all the way through. It has only been up for a few weeks so you may not have seen it. It details many of the things you mentioned such as multithreading, lazy loading, and down sampling. They also recommend using an image cache.
Downloading the large images for each image and then down sampling is going to be very inefficient. First the download size is larger than needed. Second you need to load it into memory to perform the down sample and third down sampling is somewhat slow.
I would have the web api return you a list of thumbnail urls and full image urls that you can lazy download as the view comes on screen and use the cache to keep them around a while. Make sure you down sample the sizes of the thumbnails as well. I would then when the user clicks on an image go download the full image and on the background when it arrives down sample it before displaying it.

How to download images in background in Android GridView?

I have this GridView in android in which I display some images that should be downloaded on-demand. The problem is taht the program waits upon every image request to be downloaded completely and then moves on to the next image thus making the loading very slow. I just want to know how should I move the image downloading to the background and display the image when it's ready.
I think I should use AsyncTask for this purpose but I have no idea how should I do this?

Categories

Resources