1

In BlackBerry, my application is working perfectly fine. But one Requirement is when I load data from server, a progress bar is showing. If it takes so much time to load data from server, then I want to stop the progress bar. In BlackBerry, on back key pressed, it is not working. Please help me.

public class WaitScreen extends PopupScreen
{
   public WaitScreen(String msg) {

      super(new HorizontalFieldManager());

      add(new LabelField(msg));
      AnimatedGIFField testanimated = new AnimatedGIFField(
         (GIFEncodedImage) (GIFEncodedImage.getEncodedImageResource("ajax_loader.gif")),
         AnimatedGIFField.FIELD_HCENTER | AnimatedGIFField.FIELD_VCENTER);

      add(testanimated);
   }
}
Nate
  • 31,017
  • 13
  • 83
  • 207
Riddhi Barbhaya
  • 1,205
  • 1
  • 11
  • 19
  • What kind of progress bar are you using? – Mister Smith Sep 07 '12 at 12:44
  • @MisterSmith..I have used 1 screen (wait screen) and I have used Animated GIF field and 1 gif which contains progressbar img. I am editing in my code. pls look at it. – Riddhi Barbhaya Sep 07 '12 at 12:49
  • 1
    @MisterSmith..Please see my edited code..and when data is coming from server in background Thread, at that time I am calling this wait screen. and when response from server is received, I pop this wait screen. But if Response is delayed for some time because of any reason, Then How to pop this screen? – Riddhi Barbhaya Sep 07 '12 at 13:00
  • 1
    When you press back button what happened? To pop a screen use `UiApplication.getUiApplication().popScreen(your_popup_screen)`. – Rupak Sep 07 '12 at 16:23
  • @Rupak..When I press back button, nothing is happened just I can see running Progress bar. and when data is coming from server in background Thread, at that time I am calling this wait screen. and when response from server is received, I pop this wait screen. But if Response is delayed for some time because of any reason, Then How to pop this screen? – Riddhi Barbhaya Sep 08 '12 at 05:30
  • 2
    `when response from server is received, I pop this wait screen` - so you can pop the screen actually. Then you may need to start a `Timer` which will run after a specified time (allowable delay for data download). And on the run method of the `TimerTask` check if your data is already downloaded. If not then stop downloading data, pop the wait screen, and kill the timer. Else just kill the `Timer`. – Rupak Sep 08 '12 at 07:45
  • @Rupak..Thanks a lot..I did that way only..and now it works perfectly fine.. – Riddhi Barbhaya Sep 10 '12 at 11:15

1 Answers1

2
     public long timeout=0;

                 t.schedule(new TimerTask() {

                    public void run() 
                    {
                        // TODO Auto-generated method stub

                        timeout+=1;
                        System.out.println("Timeout value:"+timeout);
                        if(timeout>=28)
                        {
                            //timeout every 1 munite

                             System.out.println("Timeout value:"+timeout);
                             System.out.println("closing connection");


                                 try
                                 {
                                     parent.notifyDestroyed();

                                 }
                                 catch (Exception ex)
                                 {                   

                                     System.out.println("Exception is:"+ex);
                                 }
                                 this.cancel();
                     }

                    }
                }, 0, 1000);

    //           Thread.sleep(30000);

httpconn_post = (HttpConnection) Connector.open(url);

             httpconn_post.setRequestMethod(HttpConnection.POST);

           httpconn_post.setRequestProperty("Accept_Language","en-US");
           httpconn_post.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

           OutputStream out = httpconn_post.openOutputStream();

           out.write(param.getBytes());
           out.flush();

           System.out.println("Status Line Code: " + httpconn_post.getResponseCode());
           System.out.println("Status Line Message: " + httpconn_post.getResponseMessage());

           if ( httpconn_post.getResponseCode()== HttpConnection.HTTP_OK )
           {
           is=httpconn_post.openDataInputStream();

//           cancelling timer

           t.cancel();
.....
.....
}



 I had done this using this code..I had done it successfully..
Riddhi Barbhaya
  • 1,205
  • 1
  • 11
  • 19