我有一个屏幕名称 DownloaderScreen屏幕启动时它将开始下载一些文件,下载完成后它将自动前进到下一个屏幕。我使用以下代码。
public DownloaderScreen() {
super(NO_VERTICAL_SCROLL | NO_HORIZONTAL_SCROLL | USE_ALL_HEIGHT
| USE_ALL_WIDTH);
this.application = UiApplication.getUiApplication();
HorizontalFieldManager outerBlock = new HorizontalFieldManager(USE_ALL_HEIGHT);
VerticalFieldManager innerBlock = new VerticalFieldManager(USE_ALL_WIDTH | FIELD_VCENTER);
innerBlock.setPadding(0, 10, 0, 10);
outerBlock.setBackground(BackgroundFactory
.createBitmapBackground(LangValue.dlBgimg));
outerBlock.add(innerBlock);
add(outerBlock);
phraseHelper = new PhraseHelper();
final String[][] phraseList = phraseHelper.getDownloadList();
gaugeField = new GaugeField("Downloading ", 0, phraseList.length, 0, GaugeField.PERCENT);
innerBlock.add(gaugeField);
Thread dlTread = new Thread() {
public void run() {
startDownload(phraseList);
}
};
dlTread.start();
}
private void startDownload(String[][] phraseList){
if(phraseList.length!=0){
for(int i=0; i < phraseList.length ; i++){//
gaugeField.setValue(i);
// code for download
}
}
goToNext();
}
private void goToNext() {
final Screen currentScreen = application.getActiveScreen();
if (UiApplication.isEventDispatchThread()) {
application.popScreen(currentScreen);
application.pushScreen(new HomeScreen());
} else {
application.invokeLater(new Runnable() {
public void run() {
application.popScreen(currentScreen);
application.pushScreen(new HomeScreen());
}
});
}
}
该代码工作正常并开始下载文件,下载完成后将进入下一个屏幕。但是当没有文件要下载时,phraseList
数组长度为零,就不往前走。我的代码有什么问题?