views:

49

answers:

3

For my BlackBerry application, I am using a single thread to retrieve images from the server one at a time. My application has a number of images and it takes too long to load all the images. How can I speed this up?

+1  A: 

Use multiple threads instead of one. Also, if this is a server that you control, consider pre-sizing the images for the target devices or having the device send its size to the server to generate and cache device specific images.

Peter DeWeese
+3  A: 

If these are static images, you can also do something like CSS sprites - stitch them all together into one big image, then in code you display the portion of the large image that corresponds to the original image you want.

The last two arguments to Graphics.drawImage(...) indicate where to start drawing from the original image, and that's how you would select the part you want.

Michael Donohue
+1 because the latency to establish a new HTTP connection over mobile can be longer than the actual time to transfer the data (for small files) - so anything you can do to minimize connections will help
Marc Novakowski
A: 

@Peter Threads on a mobile phone is a bad idea. Firstly threading on phones suck! secondly phones can't really handle more then one http connection at a time stuff bombs out.

@Userbb You can do sneeky things like stream them via a socket connection OR include multiple images in a single http request (creating a connection and http headers have overhead).

and also deff do what @peter suggested about resizing serverside.

drubin
I'm not talking about 10 threads for 10 images. Maybe 2 or 3 threads total. It works well when most of the lag is in IO waits.
Peter DeWeese
For resizing server-side, you could use a host of tools, such as imagemagick.
Peter DeWeese
I know you didn't mean 10 threads. I mean phones (excluding android and iphone smart phones) have shocking internet connections from apps some even bomb out if the browser is still open in the back ground.
drubin
BTW I am speaking from extensive testing experience not just because. Also including multiple images in a single http request is the exact same thing as sprites mentioned above. FYIEDIT: enter is mapped to save.
drubin