×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    33

    About setCurrent()

    Hi,
    How to let the display refreshed immediately after calling the setCurrent()?Because sometimes there is a delay.

    Br

    linbo

  2. #2
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280
    The thread that takes care of refreshing the screen is the UI thread. It is the same thread that runs commandAction(), itemStateChaged() on Screens, and paint(), keyPressed(), keyReleased(), etc. on Canvases. So if you're doing lengthy processing in those methods and they are the ones changing the displayable then the change will take some time to take effect. Instead run the lengthy processes in a new thread.
    For example:
    Code:
    public void commandAction(Command c, Displayable d) {
      if (c == someCommand) {
        Display.getDisplay(myMIDlet).setCurrent(someNewScreen);
        aFunctionThatTakesALongTime();
      }
    }
    In this code the displayable won't change until aFunctionThatTakesALongTime() returns, because aFunctionThatTakesALongTime() is running in the UI thread. Instead you should do something like:
    Code:
    public void commandAction(Command c, Displayable d) {
      if (c == someCommand) {
        Display.getDisplay(myMIDlet).setCurrent(someNewScreen);
        Thread t = new Thread(this);
        t.start();
      }
    }
    public void run() {
      aFunctionThatTakesALongTime();
    }
    This way you start a new thread to perform the lengthy function and set the UI thread free and able to take care of the call to setCurrent().

    shmoove

  3. #3
    Registered User
    Join Date
    Nov 2003
    Posts
    33

    Thanks a lot

    I will try.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×