06-13-2013 06:55 PM
I recently started creating a new app and I use quite a few images in it. The problem is, using so many images cause the app size to be rathr bigger than what I'd like it to be, so I was thinking that using a URL connection to these images to display them, instead of adding all of them in the res folder will save a lot of space. However, I am still very new to Java and Blackberry development.
I have searched around a lot on Google and other sites like Stackoverflow, but none of those answers actually helped me. So basically my question is, how do I display an image from a URL (ex. www.picbase.com/mylogo.jpg) unto my screen? And how can I use a indicator like the ActivityIndicator to actually show that my app is trying to load something in the background? Can anyone maybe provide me with some useful example code that I could use? It will be appreciated very much.
06-14-2013 02:28 AM
06-14-2013 04:31 AM - edited 06-14-2013 04:31 AM
Search the forum for "image URL" as there are many other Threads on this or similar topics.
This is the closest thing to what you want that I have seen:
However this code in itself has a number of things I don't like (for example, why convert to a String and then back to bytes), but it has the basics. But even if you use this, if you have a page with loads of images you can run into errors with Threading, So for image processing like this you really need a Thread pool, and that all gets quite complicated.
Also of course, unless you 'cache' or store these images, each time the user runs your app, he or she downloads the images again. For some apps of course, downloading them all the time is a requirement because they change.
In your case, I suspect the images don't change, so I would consider a one off download, as part of the 'installation', then store the images on the SD Card. If you think this is a good idea, then perhaps this sample will help:
06-14-2013 06:50 AM
Check this STACKOVERFLOW Link
I think this one you are asking....!
06-14-2013 07:36 AM
The way it reads the bytes was one of the other things that I did not like about the link I posted previously. However there are issues with the code supplied above too. For example:
Should in fact just be:
Downloading images on the fly is a nice idea in practice but has some significant issues. So as I suggested, if you don't have to do it, don't.