Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android fast Bitmap loading

I have a block of images that I want to load on my screen. All the images are files that I downloaded and stored on SD-CARD.

So far I found two ways to do it, first is loading them on the main thread, when the activity is starting, (I got about 70 images and it takes me about 2.1 seconds to load them all).

Another way is what I am testing right now. Load them on separated thread, so meanwhile I can show loading animation for the user. For now my implemintation with ThreadPoolExecutor took 4.3 sec. I did it on 10 threads.

And the last method, (it's the only thing that I didn't test yet) is working with sprite sheet.

I can't use application cache because in my application I have lots of screens and each screen has its own images set.

What do you think, what is the fastest way to load large amount of images and what acceleration technics do you know that can help me up?

like image 777
Ilya Gazman Avatar asked Feb 16 '12 21:02

Ilya Gazman


1 Answers

  1. Don't load on main thread. With 2.1 sec delay you're close to being killed with ANR (app not responding) error if you block main thread.

  2. Load in separate thread. Don't create 10 threads, but one AsyncTask, and load all your images one after another in doInBackground.

    Loading in AsyncTask should take (nearly) same time as loading in main thread. Don't put too much fancy animations, so that main thread doesn't consume too much CPU time.

like image 173
Pointer Null Avatar answered Sep 27 '22 19:09

Pointer Null