问题
In my app I fave some screens one after another, and I need to pop to home screen any time. Is there any way to find out is active screen is the first one? Or, may be, there is any function to pop to root screen without cycle of poping to previous ones?
EDIT In different words, I need my app to go to previous screen on click on blackberry "back" button (it do this without any additional code), and go to the screen, user first see when starts this application on click on "Home" button from my user interface
回答1:
This helps you any time and any where:
Write this method in startup class(StartUp.java):
public static void popupScreens()
{
int screenCount = UiApplication.getUiApplication().getScreenCount();//Gives how many screens are active state in background;
for (int i = 0; i < screenCount; i++)
{
Screen screen = UiApplication.getUiApplication().getActiveScreen();
UiApplication.getUiApplication().popScreen(screen);
}
}
and call this method at any place with class name(EX: StartUp.popupScreens) in any where then it popup all the screens in the stack.
回答2:
First, you will need to organize your screens, application logic and clearly define what screens you want to be on the UI stack and those that don't. For those screens that don't need to be on UI stack, you can dismiss them automatically when another screen is pushed on top of it:
class SplashScreen extends FullScreen
{
protected void onObscured()
{
close();
}
}
回答3:
Add menu to the Screen for having option Gotohomescreen
some thing like this. Just pop the active screen from the display stack an push your home screen from the menus's run()
method. For efficiently. If you want to go back in your application you can pop the active screen and it will go to that screen from where you have come.Let suppose you have added a backButton
you can just override the fieldchanged method of the button and in fieldchanged method do something like this.
if(field == backbutton) {
UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());
}
using the memory here is your answer
The screen at the top of the stack is the active screen that the BlackBerry device user sees. When a BlackBerry device application displays a screen, it pushes the screen to the top of the stack. When a BlackBerry device application closes a screen, it removes the screen off the top of the stack and displays the next screen on the stack, redrawing it as necessary. Each screen can appear only once in the display stack. The BlackBerry JVM throws a runtime exception
if a Screen that the BlackBerry device application pushes to the stack already exists.
A BlackBerry device application must remove screens from the display stack when the BlackBerry device user finishes interacting with them so that the BlackBerry device application uses memory efficiently
来源:https://stackoverflow.com/questions/8380558/pop-to-home-screen