Note that there are some explanatory texts on larger screens.

plurals
  1. POj2me network connection
    primarykey
    data
    text
    <p>I have read in many places that network connection in a j2me app should be done in a separate thread. Is this a necessity or a good to have? </p> <p>I am asking this because I could not find anywhere written that this must be done in a separate thread. Also, when I wrote a simple app to fetch an image over a network and display it on screen (without using a thread) it did not work. When I changed the same to use a separate thread it worked. I am not sure whether it worked just because I changed it to a separate thread, as I had done many other changes to the code also. </p> <p>Can someone please confirm?</p> <p><strong>Edit:</strong> If running in a separate thread is not a necessity, can someone please tell me why the below simple piece of code does not work? </p> <p>It comes to a stage where the emulator asks "Is it ok to connect to net". Irrespective of whether I press an "yes" or a "no" the screen does not change. </p> <pre> <code> public class Moo extends MIDlet { protected void destroyApp(boolean arg0) throws MIDletStateChangeException { // TODO Auto-generated method stub } protected void pauseApp() { } protected void startApp() throws MIDletStateChangeException { Display display = Display.getDisplay(this); MyCanvas myCanvas = new MyCanvas(); display.setCurrent(myCanvas); myCanvas.repaint(); } class MyCanvas extends Canvas { protected void paint(Graphics graphics) { try { Image bgImage = Image.createImage(getWidth(), getHeight()); HttpConnection httpConnection = (HttpConnection) Connector .open("https://stackoverflow.com/content/img/so/logo.png"); Image image = Image.createImage(httpConnection .openInputStream()); bgImage.getGraphics().drawImage(image, 0, 0, 0); httpConnection.close(); graphics.drawImage(bgImage, 0, 0, 0); } catch (IOException e) { e.printStackTrace(); } } } } </code> </pre> <p><strong>Edit</strong>: I got my answer for the code <a href="http://developers.sun.com/mobility/midp/ttips/threading3/index.html" rel="nofollow noreferrer">here</a>.</p> <p><strong>Edit:</strong> I spawned off a separate question of this <a href="https://stackoverflow.com/questions/867660/j2me-networking-threads-and-deadlocks">here</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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