如何导航回Blackberry中的上一个屏幕?

时间:2022-06-22 20:04:57

In Blackberry I can navigate from one screen to the next screen, but I can't navigate back to the previous screen. Pressing the escape 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 navigate back? If you know please help me.

在Blackberry中,我可以从一个屏幕导航到下一个屏幕,但我无法导航回上一个屏幕。按模拟器中的转义键可终止整个应用程序。模拟器中是否有任何其他键可以转到上一个屏幕或任何导航回来的代码?如果你知道请帮助我。

2 个解决方案

#1


As Andrey said, there is a display stack, so if you push screens without popping them, they will stay in stack, so closing current screen, previous screen will be shown automattically, and if there is no prev. screen, application will close.

正如安德烈所说,有一个显示堆栈,所以如果你按下屏幕而不弹出它们,它们将保持堆叠状态,因此关闭当前屏幕,前一个屏幕将自动显示,如果没有上一个。屏幕,应用程序将关闭。

However it's not good to hold many screens in display stack, so you can implement kind of stack inside of screens, to handle navigation manually.

但是,在显示堆栈中保留许多屏幕并不好,因此您可以在屏幕内实现堆栈类型,以手动处理导航。

Abstract screen class for screen stack implementation:

屏幕堆栈实现的抽象屏幕类:

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);
    }
}

Sample 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());
        }
    }
}

Sample second screen:

第二个屏幕示例:

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;
    }
}

#2


The BlackBerry maintains a stack of screens; the display stack.

黑莓手机保持着一叠屏幕;显示堆栈。

Screens are popped onto the stack, and popped off the stack through the UiApplication in charge of them. Popping the last screen off the stack closes the application by default.

屏幕弹出到堆栈中,并通过负责它们的UiApplication从堆栈中弹出。默认情况下,从堆栈弹出最后一个屏幕会关闭应用程序。

If you are running a UiApplication, named MyUiApplication, you can add the screen to the stack by calling pushScreen(new SomeScreen());

如果您正在运行名为MyUiApplication的UiApplication,则可以通过调用pushScreen(new SomeScreen())将屏幕添加到堆栈中;

The screen, if derived from MainScreen, as most BlackBerry screens are, is created with the DEFAULT_CLOSE flag, meaning that the ESCAPE button on the BlackBerry will naturally close the screen, causing popScreen() to be called. You can, of course, call popScreen() following any keypress or trackwheel/trackball click. The screen can also call close() on itself, which has the same result; the screen is popped off the stack, returning the application to the previous screen, or terminating the application if the last screen is popped off the display stack.

屏幕(如果从大多数BlackBerry屏幕派生自MainScreen)使用DEFAULT_CLOSE标志创建,这意味着BlackBerry上的ESCAPE按钮将自然关闭屏幕,从而导致调用popScreen()。当然,您可以在任何按键或拨轮/轨迹球点击后调用popScreen()。屏幕也可以自己调用close(),结果相同;屏幕弹出堆栈,将应用程序返回到上一个屏幕,或者如果最后一个屏幕弹出显示堆栈,则终止应用程序。

If the application is not created as a UiApplication, or if the screen was initially pushed onto the display stack from a non-UI thread (such as a background thread), then one must make sure that the call to close the screen is also done from the UI thread. This can be done by making sure that the eventLock is taken on the Application class prior to performing any UI operation (one would typically call invokeLater as well, in this situation).

如果应用程序未创建为UiApplication,或者屏幕最初是从非UI线程(例如后台线程)推送到显示堆栈,则必须确保关闭屏幕的调用也已完成来自UI线程。这可以通过确保在执行任何UI操作之前在Application类上采用eventLock来完成(在这种情况下,通常也会调用invokeLater)。

If the original screen was popped onto the stack as a global screen (modeless, on top of all other screens), then it must be popped off the stack using something like:

如果原始屏幕作为全局屏幕弹出到堆栈中(无模式,在所有其他屏幕之上),则必须使用以下内容将其从堆栈中弹出:

Ui.getUiEngine().dismissStatus(this);

In any case, overriding onClose() and close() of the derived Screen will allow you to trap the occurring exception for debugging and further analysis.

在任何情况下,覆盖派生屏幕的onClose()和close()将允许您捕获发生的异常以进行调试和进一步分析。

#1


As Andrey said, there is a display stack, so if you push screens without popping them, they will stay in stack, so closing current screen, previous screen will be shown automattically, and if there is no prev. screen, application will close.

正如安德烈所说,有一个显示堆栈,所以如果你按下屏幕而不弹出它们,它们将保持堆叠状态,因此关闭当前屏幕,前一个屏幕将自动显示,如果没有上一个。屏幕,应用程序将关闭。

However it's not good to hold many screens in display stack, so you can implement kind of stack inside of screens, to handle navigation manually.

但是,在显示堆栈中保留许多屏幕并不好,因此您可以在屏幕内实现堆栈类型,以手动处理导航。

Abstract screen class for screen stack implementation:

屏幕堆栈实现的抽象屏幕类:

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);
    }
}

Sample 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());
        }
    }
}

Sample second screen:

第二个屏幕示例:

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;
    }
}

#2


The BlackBerry maintains a stack of screens; the display stack.

黑莓手机保持着一叠屏幕;显示堆栈。

Screens are popped onto the stack, and popped off the stack through the UiApplication in charge of them. Popping the last screen off the stack closes the application by default.

屏幕弹出到堆栈中,并通过负责它们的UiApplication从堆栈中弹出。默认情况下,从堆栈弹出最后一个屏幕会关闭应用程序。

If you are running a UiApplication, named MyUiApplication, you can add the screen to the stack by calling pushScreen(new SomeScreen());

如果您正在运行名为MyUiApplication的UiApplication,则可以通过调用pushScreen(new SomeScreen())将屏幕添加到堆栈中;

The screen, if derived from MainScreen, as most BlackBerry screens are, is created with the DEFAULT_CLOSE flag, meaning that the ESCAPE button on the BlackBerry will naturally close the screen, causing popScreen() to be called. You can, of course, call popScreen() following any keypress or trackwheel/trackball click. The screen can also call close() on itself, which has the same result; the screen is popped off the stack, returning the application to the previous screen, or terminating the application if the last screen is popped off the display stack.

屏幕(如果从大多数BlackBerry屏幕派生自MainScreen)使用DEFAULT_CLOSE标志创建,这意味着BlackBerry上的ESCAPE按钮将自然关闭屏幕,从而导致调用popScreen()。当然,您可以在任何按键或拨轮/轨迹球点击后调用popScreen()。屏幕也可以自己调用close(),结果相同;屏幕弹出堆栈,将应用程序返回到上一个屏幕,或者如果最后一个屏幕弹出显示堆栈,则终止应用程序。

If the application is not created as a UiApplication, or if the screen was initially pushed onto the display stack from a non-UI thread (such as a background thread), then one must make sure that the call to close the screen is also done from the UI thread. This can be done by making sure that the eventLock is taken on the Application class prior to performing any UI operation (one would typically call invokeLater as well, in this situation).

如果应用程序未创建为UiApplication,或者屏幕最初是从非UI线程(例如后台线程)推送到显示堆栈,则必须确保关闭屏幕的调用也已完成来自UI线程。这可以通过确保在执行任何UI操作之前在Application类上采用eventLock来完成(在这种情况下,通常也会调用invokeLater)。

If the original screen was popped onto the stack as a global screen (modeless, on top of all other screens), then it must be popped off the stack using something like:

如果原始屏幕作为全局屏幕弹出到堆栈中(无模式,在所有其他屏幕之上),则必须使用以下内容将其从堆栈中弹出:

Ui.getUiEngine().dismissStatus(this);

In any case, overriding onClose() and close() of the derived Screen will allow you to trap the occurring exception for debugging and further analysis.

在任何情况下,覆盖派生屏幕的onClose()和close()将允许您捕获发生的异常以进行调试和进一步分析。