2012-01-11 5 views
0

ネットワーク機能を使用するBlackberryのアプリケーションを開発しています。あなたがTimeOutThreadを参照してHttpHelper両方彼らは実行の主な流れの外に呼び出すことができるように、スレッドから継承することができたようネットワークスレッドをブロックするUI

mainButton=new BitmapButton(Bitmap.getBitmapResource("elcomercio.​gif"), Bitmap.getBitmapResource("elcomercio.gif"), Field.FOCUSABLE){ 
     protected boolean navigationClick(int status,int time) { 
      //It automatically add itself to the screen stack 
      waitScreen=new WaitScreen(); 
      TimeOutThread timeOut=new TimeOutThread(HomeScreen.this, 10000); 
      HttpHelper helper=new HttpHelper("http://www.elcomercio.com/rss/latest", null, HomeScreen.this, HttpHelper.GET); 
      UiApplication.getUiApplication().invokeLater(timeO​ut); 
      UiApplication.getUiApplication().invokeLater(helpe​r); 
      return true; 
     } 
    }; 

:要求は、次のコードでは、ボタンを押すことで実行されます。また、それらの両方はデリゲートオブジェクトとして現在のScreenを受け取るので、後でメソッドを画面上で実行できます。この場合、timeoutは次の関数を実行します。タイムアウトメソッドが呼び出されたsucessfully

public void onTimeout() { 
    if(!didTimeout.booleanValue()){ 
     UiApplication.getUiApplication().popScreen(waitScr​een); 
     didTimeout=Boolean.TRUE; 
    } 
} 

...でも、待機画面はsucessfully poppedOutで、最後の画面を示しましたさ。しかし、その時点でUIがハングしています...私が持っていたHttpThreadのように、UIをブロックしています...ネットワークスレッドがタイムアウトすると、UIが再び応答するためです。私が間違っているのは何ですか?

答えて

1

UiApplication.invokeLater()は、実行スレッドでThreadオブジェクトを実行しません。代わりにメインイベントディスパッチスレッド(UIを実行する同じスレッド)でオブジェクトを実行します。 UiApplication.invokeLater()メソッドの代わりにThread.start()メソッドを使用する必要があります。例:

mainButton = new BitmapButton(Bitmap.getBitmapResource("elcomercio.​gif"), Bitmap.getBitmapResource("elcomercio.gif"), Field.FOCUSABLE) 
{ 
    protected boolean navigationClick(int status,int time) 
    { 
     waitScreen = new WaitScreen(); 
     TimeOutThread timeOut=new TimeOutThread(HomeScreen.this, 10000); 
     HttpHelper helper = new HttpHelper("http://www.elcomercio.com/rss/latest", null, HomeScreen.this, HttpHelper.GET); 
     timeO​ut.start(); 
     helpe​r.start(); 
     return true; 
    } 
}; 
関連する問題