黑莓加载屏幕:按回到去加载屏幕
问题描述:
这里是我的UiApplication类:黑莓加载屏幕:按回到去加载屏幕
public class HelloWorld extends UiApplication {
public HelloWorld(){
pushScreen(new LoadingScreen());
Ui.getUiEngineInstance().setAcceptableDirections(Display.DIRECTION_PORTRAIT);
}
public static void main(String[] args){
HelloWorld theapp = new HelloWorld();
theapp.enterEventDispatcher();
}
}
的loadingScreen类:
public class LoadingScreen extends CustomMainScreen {
public LoadingScreen(){
Bitmap tcalogo = Bitmap.getBitmapResource("loading_360.png");
BitmapField tcalogoField = new BitmapField(tcalogo);
add(tcalogoField);
startLoading();
}
public void startLoading(){
ConsumeFactoryThread consumption = new ConsumeFactoryThread("http://example.com",this); //add arguments of url and scope
consumption.start();
}
public void onFinish(JSONArray array){ //method that executes when the json is retrieved
UiApplication.getUiApplication().pushScreen(new FeaturedScreen(array));
}
}
我把它打开一个线程loadingscreen,下载JSON,那么在loading Screen方法中运行onFinish方法,并使用检索到的信息推送新屏幕。它的工作原理,线程/下载不是我的问题,但它是用户按下并返回到加载屏幕的能力。我有这样的方式从堆栈中进行加载,但我不确定这是否是“正确”的方式。
如何使用loadingScreen一次?
答
从代码的外观,您正在推动加载屏幕,然后通过onFinish方法将精选屏幕推到堆栈上。
使用后退键,它将循环通过已经推入堆栈的屏幕。
我可以建议使用艰难:
public void onFinish(JSONArray array) {
UiApplication.getUiApplication()
.pushScreen(new FeaturedScreen(array));
try {
UiApplication.getUiApplication().popScreen(this);
} catch(IllegalArgumentException e) {
//somehow the screen isn't on the stack
//Do nothing.
}
}
这应该从栈中删除LoadingScreen所以当你压回,它不再进入这个画面。