Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 237
Registered: ‎05-07-2010
My Device: 8520
My Carrier: Internet
Accepted Solution

How to retrieve image in background?

Hi,

 

I am just using static method for streamconnection to retreive images over from server.

 

Now my problem is that it takes to much time to load.

 

so i want that at the first just insert null images to all the fields and there after as the thread retrieves the image same time it will update the field with that image.

 

 

thankx.

 

 

___________________________________________________
please press kudos(star button on left) if this post is helpful to you
"Accept as solution" if your query has been resolved.@hitendra
_________________________________________________
Developer
Posts: 950
Registered: ‎06-22-2010
My Device: 9550

Re: How to retrieve image in background?

Why don't you use the HttpConnection instead of StreamConnection.

And image Size is to Big or small. It should not take much time to download.

------------------------------------------------------------------------------------
Press Kudo to say thank to developer.
Also Press the Accept as solution Button when u got the Solution.

 

Developer
Posts: 237
Registered: ‎05-07-2010
My Device: 8520
My Carrier: Internet

Re: How to retrieve image in background?

ok

if i am using httpconnection and if there are number of images then what?

 

so what i want is first initially load 5 or 10 images to the screen there after as the images retrieve draw them to the screen.

___________________________________________________
please press kudos(star button on left) if this post is helpful to you
"Accept as solution" if your query has been resolved.@hitendra
_________________________________________________
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to retrieve image in background?

Not sure how we can help here. The approach you are suggesting is exactly what i would recommend.  Start a background Thread, have it process a list of images, and as they arrive, advise the Ui Processing so that it can update the screen. 

Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: How to retrieve image in background?

Get familiar with "observer pattern":

Observer pattern - Wikipedia

 

In your case, observer (or listener, in BlackBerry speak) will be your UI element which wants to paint the image.  Initially, you will have null as the reference to the image and your paint() method will skip painting it.

Later, once the image is downloaded in a separate thread, that thread will notify your UI via some listening method registered to be notified about that image.  That method will populate your internal reference to the image and call invalidate().

invalidate() will cause your paint() method to be called.  At this point, paint() will notice a non-null reference to the image and will draw it as intended.

 

There might be other approaches - the above is one of the many. It is both object-oriented and efficient enough.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Highlighted
Developer
Posts: 237
Registered: ‎05-07-2010
My Device: 8520
My Carrier: Internet

Re: How to retrieve image in background?

thankx arkadyz

___________________________________________________
please press kudos(star button on left) if this post is helpful to you
"Accept as solution" if your query has been resolved.@hitendra
_________________________________________________