×

Discussion Board

Results 1 to 10 of 10
  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    5

    Displaying status while connecting to a HTTP URL

    Hi all,

    My application connects to a URL, and I create a new Form which is supposed to display a gauge as a status indicator. The form is in a new thread, and I am connecting to the HTTP URL in the same thread. When I say display.setCurrent(Form) the thread is created and the function executes, but the Form doesnt display. I start the thread before setting the display.

    Any suggestions anyone????? And this is kinda urgent so I need a quick reply, pleaaaaaaaasssssssseeee

    Regards

    Vishal

  2. #2
    Regular Contributor
    Join Date
    Apr 2003
    Location
    Slovakia/Bratislava
    Posts
    67
    You have possible bad design, according to my knowledge from other platforms, you have to "synchronize" all working threads with GUI thread...you have to do all the gui actions in gui thread...

    Tom

  3. #3
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395
    Hi!

    First, are you looking at the 7210 emulator, or a real phone? I find that screen update on the emulator sometimes lag behind what's going on. I use "progress" and "busy" type screens, which appear perfectly on a real 6100, but are delayed in appearance on the 7210 sim.

    Second, I use Canvas subclasses for status display. You have much more control of when repainting occurs with a Canvas. With a Form, you rely on the device generating a repaint - with a Canvas, you can generate the event yourself, or use serviceRepaints() to make it happen synchronously.

    Also, you can use the callSerially() method of Display to help you synchronize the start of your work to the processing of the paint event. That way you know the screen will appear before processing starts. I use a run() method something like:

    private Thread m_thd;

    public void run () {
    if (m_thd == null) {
    m_thd = new Thread (this);
    m_thd.start ();
    return;
    }

    // real work goes here
    }

    I kick this off using callSerially(), with m_thd set to null. That way, no work starts in run() until after my status screen has painted.

    Hope this helps!!

    Cheers,
    Graham.

  4. #4
    Registered User
    Join Date
    Jul 2003
    Location
    Finland, Tampere
    Posts
    1,113
    I had kind of similar problem.
    The point is that System switches screens (requested in Display.setCurrent()) when it has time. Basically this means that to be sure about switching happend you should
    1) request switching
    2) end operations (end current control thread, return from all functions)
    3) catch switching event (use showNotify() or callSerially())
    4) continue operations.

    Maybe there is some other way using tricky thread synchronizations, BUT according to MIDP specification when to do switching is up to device manufacturer. Hence, it's hard to be sure that same kind of synchronization will work on every phone.
    That's why I use procedure described earlier

    P.S.
    If you are developing game, you usually use Canvas of FullCanvas almost everywhere. In this case it's better not to do any screen switching at all to avoid these issues Just draw everything on the same Canvas

  5. #5
    Regular Contributor
    Join Date
    Apr 2003
    Posts
    184
    Hi vishaljumani,
    You have to do the update of the From (i.e. displaying the Gauge)
    in the calling Thread and the HTTP connection in the new Thread.
    It will fix the problem.

  6. #6
    Registered User
    Join Date
    Jul 2003
    Location
    Finland, Tampere
    Posts
    1,113
    zivgr
    You have to do the update of the From (i.e. displaying the Gauge)
    in the calling Thread and the HTTP connection in the new Thread.


    He has to display this Form first
    His problem was that form is not shown when he wants it to display.

  7. #7
    Regular Contributor
    Join Date
    Jul 2003
    Posts
    63
    I have exactly the same problem:

    Before I make an HTTP connection I want to display a Gauge to show the status of the connection but the Form which contains the Gauge is never displayed.

    display.setCurrent(progressForm);
    Thread thread = new Thread(this);
    thread.start();

    and in the run() method I make the connection and update the Gauge status.
    But the HTTP connection does it's job and the Form with Gauge never shows up.

    I've read on this thread

    Developer Discussion Boards > > Java > J2ME (general) > Please help: Display.setCurrent() delay

    to wait until the current display is set to the Form containing the Gauge and only after to do the HTTP connection;

    So, at the beginning of the run() method I make a

    while( display.getCurrent () ! = progressForm){
    }

    but no result; it just blocks the application.

    The problem only happens on the 7210 emulator; in the Series 60 emulator works just fine;

    (the photoalbum example that comes with wtk2 has the same problem on the 7210 emulator : the progress gauge is never displayed);

    Any suggestions how can I make this work?

  8. #8
    Regular Contributor
    Join Date
    Jul 2003
    Posts
    63
    It works !!!

    The second approach works (I think I forgot to recompile before testing):

    at the beginning of the run method, just put a

    while(!display.getCurrent().equals(progressForm)){
    }

    or , the same thing

    while(display.getCurrent().equals(oldScreen)){

  9. #9
    Registered User
    Join Date
    Jul 2003
    Location
    Finland, Tampere
    Posts
    1,113
    ionutianasi

    Try using callSerially() instead of Thread.start() sequence.
    And actually start networking threads in a run method().

    The problem only happens on the 7210 emulator; in the Series 60 emulator works just fine;

    Screen switching problems are known issue for Series 40
    Basically it switches screen only when it has absolutely nothing to do.

    I was facing this problem quite long ago, so I'm not sure that my proposal will solve the problem.
    Please post your results here.

    P.S.
    I assume that in your first example after Thread.start() you ended your current thread operations, exited.

  10. #10
    Regular Contributor
    Join Date
    Jul 2003
    Posts
    63

    doctordwarf

    Thanks for replaying!

    I've already solved the problem, look above...

    Before doing the "while" thing I've tried with callSerially but didn't work.

Posting Permissions

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