How to go to the previous screen in Blackberry?

In Blackberry, I can go from one screen to the next screen, but I can’t go back to the previous screen. Pressing the evacuation key in the emulator terminates the entire application. Is there any other key in the emulator to go to the previous screen or any code to go back? If you know, please help me.

+5
source share
2 answers

As Andrei said, there is a stack of exhibits, so if you click screens without them appearing, they will remain on the stack, so closing the current screen, the previous screen will be displayed automatically, and if not, then a preview. screen, the application will close.

However, it’s not very convenient to store many screens in the display stack, so you can implement the stack view inside the screens to handle manual navigation.

An abstract screen class for implementing a screen stack:

public abstract class AScreen extends MainScreen {
    Screen prevScreen = null;

    void openScreen(AScreen nextScreen) {
        nextScreen.prevScreen = this;
        UiApplication.getUiApplication().popScreen(this);
        UiApplication.getUiApplication().pushScreen(nextScreen);
    }

    void openPrevScreen() {
        UiApplication.getUiApplication().popScreen(this);
        if (null != prevScreen)
            UiApplication.getUiApplication().pushScreen(prevScreen);
    }
}

Example of the first screen:

public class FirstScreen extends AScreen implements FieldChangeListener {

    ButtonField mButton = null;

    public FirstScreen() {
        super();
        mButton = new ButtonField("Go second screen", ButtonField.CONSUME_CLICK);
        mButton.setChangeListener(this);
        add(mButton);
    }

    public void fieldChanged(Field field, int context) {
        if (mButton == field) {
            openScreen(new SecondScreen());
        }
    }
}

Second screen example:

public class SecondScreen extends AScreen implements FieldChangeListener {

    ButtonField mButton = null;

    public SecondScreen() {
        super();
        mButton = new ButtonField("Go first screen", ButtonField.CONSUME_CLICK);
        mButton.setChangeListener(this);
        add(mButton);
    }

    public void fieldChanged(Field field, int context) {
        if (mButton == field) {
            openPrevScreen();
        }
    }

    public boolean onClose() {
        openPrevScreen();
        return true;
    }
}
+16
source

BlackBerry supports a stack of screens; display stack .

UiApplication. .

UiApplication MyUiApplication, , pushScreen ( SomeScreen());

, MainScreen, BlackBerry, DEFAULT_CLOSE, , ESCAPE BlackBerry , popScreen(). , , popScreen() -/. close(), ; , , .

UiApplication, , UI (, ), , . , , eventLock Application - ( invokeLater , ).

(, ), , - :

Ui.getUiEngine() dismissStatus ();.

onClose() close() .

+13

All Articles