从另一个启动一个BlackBerry屏幕

时间:2010-04-16 12:20:42

标签: multithreading user-interface blackberry screen

我最近遇到了一个障碍,同时为我的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);
}

有谁知道如何解决从登录屏幕无缝移动到加载屏幕到主屏幕的问题?注意:一旦我进入主屏幕,我想让它成为堆叠中唯一的屏幕。

谢谢!

3 个答案:

答案 0 :(得分:2)

在这种情况下,您可能需要先按应用程序的主屏幕,然后再按下登录屏幕。我不确定你的情况,但这是我正在做的假设:

  • 您正在存储登录信息
  • 如果未存储登录信息,则按下登录屏幕
  • 在成功案例中,您存储登录信息并继续显示主屏幕
  • 如果登录失败或取消,则不显示主屏幕

如果这些假设合理有效,则下面的代码应该可以很好地为您服务。

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

答案 1 :(得分:1)

您是否曾尝试将主屏幕放在堆栈上(来自应用程序),如果尚未尝试登录,请按下登录屏幕?反过来,登录屏幕可以推送加载屏幕。加载完成后,将其弹出堆栈(从登录)和关闭()登录。然后,您将返回主屏幕并登录用户。

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

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

答案 2 :(得分:0)

如果您在代码中知道需要按屏幕时,可以使用UiApplication pushScreen功能。首先获取具有UI的当前应用程序的句柄:

UiApplication currentapp = UiApplication.getUiApplication();

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

currentapp.getActiveScreen();

然后您可以使用UiApplication实例推送新屏幕:

currentapp.pushScreen(homeScreen);

我希望有帮助:)