【问题标题】:Starting one BlackBerry screen from another从另一个屏幕启动一个 BlackBerry 屏幕
【发布时间】:2010-04-16 12:20:41
【问题描述】:

我最近在为我的 BlackBerry 应用程序进行最后润色时遇到了障碍。我正在构建一个登录屏幕,如果用户成功登录,它将进入数据加载屏幕,然后进入主屏幕。从主屏幕,您可以使用该应用程序。一切都很好,但有一件事,我无法从登录屏幕无缝移动到加载屏幕,再到主屏幕。我可以从登录屏幕移动到加载屏幕,因为我是通过 GUI 线程上的按钮单击来完成的,但是我在堆栈底部有登录屏幕并且无法将其取出使用解雇方法。进入加载屏幕后,我无法推送主屏幕,因为我不是通过 gui 方法进行的,尽管我可以通过以下代码更新 GUI:

   private void checkData(){

            Timer loadingTimer = new Timer();
    TimerTask loadingTask = new TimerTask()
    {

        public void run()
        {
            // set the progress bar
            progressGaugeField.setValue(DataManager.getDataLoaded());

            // for repainting the screen
            invalidate();
        }
    };
    loadingTimer.scheduleAtFixedRate(loadingTask, 500, 500);
}

有人知道如何解决我从登录屏幕无缝移动到加载屏幕再到主屏幕的问题吗?注意:一旦我在主屏幕上,我希望它成为堆栈中唯一的屏幕。

谢谢!

【问题讨论】:

  • "home screen" 代表黑莓原生主屏幕还是你的应用程序主屏幕?

标签: multithreading user-interface blackberry screen


【解决方案1】:

在这种情况下,您可能希望先推送应用程序的主屏幕,然后再推送登录屏幕。我不确定您的情况,但以下是我所做的假设:

  • 您正在存储登录信息
  • 如果未存储登录信息,则推送登录屏幕
  • 在成功的情况下,您存储登录信息并继续显示主屏幕
  • 如果登录失败或被取消,则不会显示主屏幕

如果这些假设合理有效,那么下面的代码应该很适合您。

public class YourApp extends UiApplication {
public YourApp() {
    final AppHomeScreen screen = new AppHomeScreen();
    pushScreen(screen);

    if(getLoginInfo() == null) {
        final LoginScreen loginScreen = new LoginScreen();
        this.invokeLater(new Runnable() {
            public void run() {
                pushModalScreen(loginScreen);
                if(getLoginInfo()==null)
                    popScreen(screen); //exit the app
                }
                //perhaps the loading screen populates info in your home screen then pops itself
                pushScreen(new LoadingScreen(screen));
            }
        );
    }
}

【讨论】:

    【解决方案2】:

    您是否尝试过将主屏幕首先放入堆栈(从应用程序),如果尚未尝试登录,则推送登录屏幕?反过来登录屏幕可以推送加载屏幕。加载完成后,将其从堆栈中弹出(从登录)并 close() 登录。然后,您将返回主屏幕并登录用户。

    为了使加载工作并跟踪其进度,您可以使用以下代码

    LoadingScreen lScreen = new LoadingScreen();
    getUiEngine().pushScreen(lScreen);
    _invokeIDGame = getApplication().invokeLater(new Runnable() {
        public void run() {
            // Check to see if the loading is done.
            // implement an isLoading function to determine it
            if (lScreen.isLoading() == false) {
            // Cancel invoking this piece of code again (normally is invoked
            // every 500 ms, as specified below)
            getApplication().cancelInvokeLater(_invokeIDGame);
            // Pop the loading screen off the stack, which returns the user to this screen
            getUiEngine().popScreen(lScreen);
             // close this screen
             close();
            }
        }
    }, 500, true); // rerun this code every 500ms
    

    【讨论】:

    • 你的答案也是正确的,虽然我只能选择一个。对不起。
    【解决方案3】:

    如果你在代码中知道什么时候需要推屏,可以使用UiApplication pushScreen函数。首先获取具有 UI 的当前应用程序的句柄:

    UiApplication currentapp = UiApplication.getUiApplication();
    

    您可以比较活动屏幕以验证它是您的应用程序:

    currentapp.getActiveScreen();
    

    然后你可以使用 UiApplication 实例来推送你的新屏幕:

    currentapp.pushScreen(homeScreen);
    

    希望对你有帮助:)

    【讨论】:

    • 我一直在这样做,除了 getActiveScreen()。它会导致新屏幕的绘制事件发生异常,不会打印出来:(。还有其他想法吗?
    • 所以当您尝试推送主屏幕时出现异常?哪个例外?
    • 我认为首先打开主屏幕最有意义。我可以在适当的时候填充它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-09
    • 1970-01-01
    • 2019-07-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多