Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
Posts: 13
Registered: ‎01-26-2011
My Device: Curve 3G
My Carrier: Indosat

Help with Status.show

Hi,

 

I am new in Blackberry development.

Currently, I am building an app that retrieves text from web service and displays the text to the main screen of the app.

 

I have created a separate Thread class that calls HttpConnection opening URL that calls the webservice and then, return the text if called successfully.

 

At the main screen of my app, I directly call the Thread class that I have created.  And I start the Thread.  The idea is when waiting for the HttpConnection to open the URL successfully, I want to call Status.show( "Loading" ).  I have tried putting the Status.show either inside the Thread class or the main screen, but to no avail.  Is there any simple example how to use the status message?

 

Thank you very much for your help.

Willy
Developer
Posts: 16,637
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Help with Status.show

this should help:

http://supportforums.blackberry.com/t5/Java-Development/What-is-the-Event-Thread/ta-p/446865

 

in short: you can modify the UI from your thread, but you have to use invokelater or synchronize on the event lock.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 204
Registered: ‎08-09-2010
My Device: 9930, PlayBook
My Carrier: Verizon Wireless

Re: Help with Status.show

UiApplication.getUiApplication().invokeLater(new Runnable()
{
                public void run()
                {
                    Status.show("Your Message Here");
                }
});

New Developer
Posts: 13
Registered: ‎01-26-2011
My Device: Curve 3G
My Carrier: Indosat

Re: Help with Status.show

Thank you guys for the answer.  I am able to show the status, but the status runs for only 2 seconds and the content from the HttpConnection has not finished loading.  What I want to do is : while the content is being retrieved from HttpConnection, the Status Loading keeps showing.

 

Here are some of my relevant codes :

 

---------------------------

MainScreen class :

---------------------------

 

public MainScreen()

{

     String url = "http://myWebServicesLink";


     HttpRequestDispatcher dispatcher = new HttpRequestDispatcher( url, "GET", this );
     dispatcher.start();

}


public void requestWait()

{
     UiApplication.getUiApplication().invokeLater( new Runnable() {
         public void run() {
             Status.show( "Loading.. Please Wait.." );
         }
     } );
}

 

--------------------------------------------

HttpRequestDispatcher class :

--------------------------------------------

 

public HttpRequestDispatcher( String url, String method, MainScreen screen )
{
    this.url = url;
    this.method = method;
    this.screen = screen;
}


public void run()

{

     try

     {

          HttpConnection connection = (HttpConnection) Connector.open( url );
          connection.setRequestMethod( method );


          screen.requestWait(); // this is where I call the Status Show


          int responseCode = connection.getResponseCode();

            
          if ( responseCode != HttpConnection.HTTP_OK )
          {
                screen.requestFailed( "Unexpected response code : " + responseCode );
                connection.close();
                return;
          }


         // the rest of code

     } 

     catch ( IOException ex )

     {

          screen.requestFailed( ex.toString() );

     }

}

 

What I want is : the moment the HttpConnection open is called, the status shows until the responseCode is obtained.

 

Once again, thanks for your help. :smileyhappy:

Willy
Developer
Posts: 16,637
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Help with Status.show

you can take a look at peters sample

http://supportforums.blackberry.com/t5/Java-Development/Sample-quot-Please-Wait-quot-screen-part-1/t...

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter