Here’s my uiapplication class:
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();
}
}
The loadingScreen class:
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));
}
}
I push a loadingscreen which opens a thread, downloads the json, then runs the onFinish method back in the loadingScreen method and pushes a new screen with the retrieved info. It works, the thread/download is not my problem, but it is the ability for the user to press back and return to the loadingScreen. I got this way of doing a loading off of stack, but I’m not sure if it is the “right” way.
How do I use the loadingScreen once?
From the looks of your code, you are pushing the Loading screen then pushing the Featured screen on to the stack via the onFinish method.
With the back key, it will cycle through the screens that have been pushed on to the stack.
May I suggest using trying:
This should remove the LoadingScreen from the stack so when you press back, it no longer goes to this screen.