1

在 BlackBerry 中,我的应用程序运行良好。但是一个要求是当我从服务器加载数据时,会显示一个进度条。如果从服务器加载数据需要很长时间,那么我想停止进度条。在黑莓中,按下后退键时,它不起作用。请帮我。

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);
   }
}
4

1 回答 1

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..
于 2012-09-10T11:21:12.303 回答