0
我正在开发一个使用网络功能的黑莓应用程序。该请求是通过按下一个按钮,用下面的代码执行:网络线程阻塞用户界面
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(timeOut);
UiApplication.getUiApplication().invokeLater(helper);
return true;
}
};
正如你可以看到TimeOutThread和HttpHelper无论从主题继承,使他们能够执行的主流外部调用。同样他们都会将当前屏幕作为委托对象接收,以便我可以在屏幕上稍后执行方法。在这种情况下,超时执行以下功能。
public void onTimeout() {
if(!didTimeout.booleanValue()){
UiApplication.getUiApplication().popScreen(waitScreen);
didTimeout=Boolean.TRUE;
}
}
超时方法被称为成功......甚至waitScreen弹出成功,并显示最后一个屏幕。但用户界面在那个时刻挂起......就像我的HttpThread仍在执行阻止用户界面......我知道这是因为当网络线程超时时......用户界面再次响应。我做错了什么?