×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Regular Contributor
    Join Date
    Dec 2003
    Posts
    109

    display a message while making Http Connection

    Hi. I am making an HttpConnection in my app and loading content into the application. Depending on the length of content this operation may take quite long on a regular phone and during this time the application seems as if it has stopped responding.

    So, what I would like to do is display a message (TextBox or an Alert) informing the user that application is trying to connect.

    I tried setting current displayable to Alert, and then calling the method making HttpConnection. At the end of the method, when connection has been made and data has been transferred, I am setting Displayable to a TextBox with the retrieved data.

    However, the application skips the alert screen and goes directly to making HttpConnection and the TextBox.

    So, my question is how can I display one screen until an operation is complete and then show another screen? Thank you for the input.

  2. #2
    Regular Contributor
    Join Date
    Mar 2003
    Location
    Indonesia - East Java
    Posts
    128

    Solustion

    Dear artemg,

    May be you can try make like this one for illustration we have 3 class
    1. class Main
    2. class result
    3. class error
    so at main you class you can try like this
    ...
    try
    {
    // if that result is ok going to class result
    }
    catch(IOException ioe)
    {
    // goes to class error
    }
    finally
    {
    try
    {
    // close your connection
    }
    catch(Exception e)
    {}
    }

    I hope that illustration can help you.

  3. #3
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280
    You're problem is that you're performing the networking in the UI thread. Since all the http methods are blocking methods, you're blocking the UI thread, and it's the UI thread that's in charge of changing screens. So it only gets around to changing the screen after the networking is finished, hence it skips the alert.
    You'll have to spawn a new thread to perform the networking in.
    Anytime you have some processing to do that may take a while (.5 seconds is also a while), you shouldn't do it on the UI thread (ie, in commandAction(), or keyPressed(), etc.).

    shmoove

  4. #4
    Regular Contributor
    Join Date
    Dec 2003
    Posts
    109
    Thanks a lot for your posts. I would prefer to keep my current class system and for this reason, I want to first experiments with threads.

    I constantly get the notification (on emulator) that network connections are potentially blocking and that I should perform them through thread other than command action. Until now this hasn't been an issue on the real phone and I haven't bothered (shame on me).

    My question then is "how?" - how do I spawn another thread to perform networking, if networking still needs to be performed upon user requesting info?

    Thank you!

  5. #5
    Regular Contributor
    Join Date
    Dec 2003
    Posts
    109
    Ok, never mind. CLDC documentation turns out to have a very good explanation of threads. Once again, thank you for your posts.

Posting Permissions

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