I want to download some thumbnails async in background and load them into an ImageView after download finished. For this purpose I used AsyncTask, but it's not properly working for more then 5 download at the same time. It seems like there is an internal limit of Asynctask running at the same time.
What is the right alternative to have an ulimited amount of background processes which can update the UI after finishing download?
You shouldn't be using AsyncTask anymore as it's deprecated.
I would recommend you to use a suitable library for that use case, such as Picasso or Fresco, just to mention. Not only they download images but they also handle other tasks like caching or download cancellation.
In my project a background service downloads contents from remote database using asynctask. I would like to download all images from urls (saved in database) using Picasso in background service. These images will be used later in my app.
Is there any better solution to do this? or just use the one line code of Picasso in asynctask?
Is there any better solution to do this? or just use the one line code
of Picasso in asynctask?
What do you mean by better? Is it about performance?
If you will have to download a lot of images, you might want to download them on the service. With this, your download will not stopped if the activity is destroyed.
For the library, i never use Picasso. I always use Universal Image Loader but i dont know which one is better. I think the most important feature of those libraries is their capability to cache the images.
UPDATE
For performance, you may want to combine the Picasso/UIL library with PullToRefresh library, especially when your listview/gridview want to load a lot of images.
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
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
After some googling, I selected various sources and started to use a separate thread to download images to make the UI responsive. It actually worked like a charm. But after a few minutes it would freeze the emulator. Initially I had assumed various reasons but finally I figured out that if this threading code is removed it works without freezing the emulator.
The code was adapted from another Stackoverflow question from the answer given by a certain Fedor. For the sake of simplicity I had removed the HashMap part and directly download the image each time a request comes from the list adapter. Also, I assumed that since the image is very small (< 1 KiB) it can actually be downloaded again rather than storing it in memory.
I am not sure if this is the right way to handle asynchronous image download, but any help in preventing the emulator freeze would be much appreciated. I can copy paste the code if needed.
Have a look at this url
about downloading images from remote server using asynchronous task and threadpool.