Question

I am new to BB can any body please tell me how to load images asynchronously?

I found some code but it is performing synchronously.

I have to load more than one image by using the above code like until my for loop is finished my program is ideal

Mycode

package mypackage;
import java.io.DataInputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import net.rim.device.api.system.EncodedImage;
import net.rim.device.api.ui.component.Dialog;

public class image {
public EncodedImage image(final String url){

      try
    {
         // HttpConnection hc=new Httpconnection();

          HttpConnection hc=(HttpConnection)Connector.open(url+";deviceside=true");
        hc.setRequestMethod(HttpConnection.GET);
        int st=hc.getResponseCode();
        int len=(int)hc.getLength();
        System.out.println("Code==>"+hc.getResponseCode());
        System.out.println("Message==>"+hc.getResponseMessage());
        byte bts[]=new byte[len];
       // resizeImage( bitmap, 150,150);

        DataInputStream dis=new DataInputStream(hc.openInputStream());
        dis.readFully(bts);  
        EncodedImage image;

        image=EncodedImage.createEncodedImage(bts,0,len);

        dis.close();
        hc.close();   
        return image;
  }    catch(Exception e){
       e.printStackTrace();
      Dialog.alert("Error ");
      return null;


  }
}}

`

Was it helpful?

Solution

I Have implemented like,

1) created custom field and painted one default image.

2) added image properties like url,size etc to a Object.

3) Added that Object to that Cookie

4) after adding fields to manager , started a new thread .

5) In that thread getting cookie properties and downloading each and every image .

The Above process doesnot stops you to stop download until screen gets destroyed and will download all the images.

Later you can add your requirement upon it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top