How to load images faster, smoother, and without OutOfMenory error? - android

i am trying to write a media player application. In this i have to load album art(s) from a network to GridView of android. With my initial implementation, it's working fine, but it's not fast, not smooth. Loading images(.jpeg) taking more time. I have resize the images to low resolution, even now not working. In my observation, Saavn(android application) loading album arts very fastly.
How can i load my album arts with that speed in more efficient way.
I have gone through http://www.coderzheaven.com/tag/faster-loading-images-in-gridviews-or-listviews-in-android-using-menory-caching/
but not helpful. Any other ideas?

Have you thought to use Image loading libraries?
Try to use Universal Image loader library, its good.

Try this image loading library.
Picasso
Sample code is availabe Here
Easy to integrate.

Related

efficient way to use multiple local image resources in recyclerview

I have around 200 images as vector drawables (in res folder) that i'd like to load in recyclerview. Since the size of vector drawable is not that big I've decided to store them inside the app and not set up the server or do api call. The total size of 200 images sums to 4/5 MB only. When I try to show the images in recyclerview it's creating a lag. Since Picasso and Glide are no use for vector drawables what approach would be the best to solve the lag issue? Is paging helpful for local resources?
The lag is because of the decoding of the vector into bitmap on the UI thread. You can read it here https://developer.android.com/reference/android/widget/ImageView.html#setImageResource
Quick solution would be to use any image loading library like Glide which does this stuff in background.
You can use pagination to avoid the lagging of the images while loading. It will be so fast even the app lifecycle is stopped or destroyed.
Android Paging Docs
The Paging Library helps you load and display small chunks of data at a time. Loading partial data on demand reduces usage of network bandwidth and system resources.
Here is the docs for Paging using RecyclerView
I hope it works for you.

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).

App loading time Issue- Android

I am developing an app Similar to Logo Quiz.
I have around 600 images in it.
Now when the app loads for the first time it takes a lot of time to load.
Any solution to that loading time issue?
There are a lot of solution for doing efficient asynchronous image loading. Here is a few of them:
Android Universal Image Loader
Picasso
Android-Volley
A more detailed blog post on the last 2 libs: http://blog.bignerdranch.com/3177-solving-the-android-image-loading-problem-volley-vs-picasso/
Use universal image loader
https://github.com/nostra13/Android-Universal-Image-Loader
It will load your image in background and not block the ui

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.

Categories

Resources