Note that there are some explanatory texts on larger screens.

plurals
  1. POBlackberry: opening ConnectionFactory too many times?
    text
    copied!<p>I'm not entirely sure how to use ConnectionFactory properly, but here is my ImageThread example which invokes ConnectionFactory every time there is an image, which there are a bunch on any given screen.</p> <pre><code>public class ImageThread extends Thread { private String url; private HttpConnection httpConn; private InputStream is; private JSONArray array; private Bitmap image; private ImageThreadCallback c; private static boolean hasImageCache = false; private static MultiMap imageCache; public ImageThread(String url, ImageThreadCallback c, String ident){ System.out.println("Connection begin!"); this.url = url; this.c = c; } public void notifyUs(){ this.c.update(image); } public void run(){ myConnectionFactory connFact = new myConnectionFactory(); ConnectionDescriptor connDesc; connDesc = connFact.getConnection(url); System.out.println("Connection factory!"); if(connDesc != null) { System.out.println("Connection not null!"); httpConn = (HttpConnection) connDesc.getConnection(); try { httpConn.setRequestMethod(HttpConnection.GET); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } is = null; try { final int iResponseCode = httpConn.getResponseCode(); UiApplication.getUiApplication().invokeLater(new Runnable() { public void run() { System.out.println("Connection in run!"); // Get InputConnection and read the server's response InputConnection inputConn = (InputConnection) httpConn; try { is = inputConn.openInputStream(); System.out.println("Connection got inputstream!"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } byte[] data = null; try { data = IOUtilities.streamToBytes(is); System.out.println("Connection got data!"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } EncodedImage hai = EncodedImage.createEncodedImage(data, 0, data.length); image = hai.getBitmap(); notifyUs(); } }); } catch(IOException e) { System.err.println("Caught IOException: " + e.getMessage()); } } } } </code></pre> <p>I know the example is the same as the examples, but should ConnectionFactory be called every instance of ImageThread? I ask this question because my app all of a sudden loses connection, randomly, while using it. The input/output icon ceases to flicker. I'm thinking it could be a misuse of ConnectionFactory? </p> <p>Any ideas?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload