【问题标题】:BlackBerry App: Screen Not Showing Up In Auto Run Mode黑莓应用程序:自动运行模式下不显示屏幕
【发布时间】:2012-06-27 04:19:49
【问题描述】:

我正在尝试创建一个将在系统启动时运行的后台应用程序。当我手动运行它(从功能区)时,屏幕会出现,但是当我在将其设置为启动应用程序(描述符中的启动时自动运行选项)后运行该应用程序时,屏幕上不会出现任何内容。我正在尝试以下代码;

public class AppClass extends UiApplication {

    public static void main(String[] args) {
        AppClass theApp = new AppClass();
        theApp.enterEventDispatcher();
    }

    public AppClass() {
        pushScreen(new AppScreen());
    }
}

这是屏幕类;

public final class AppScreen extends MainScreen {

    private LabelField  label;

    public AppScreen() {
        setTitle("AppTitle");

        label = new LabelField();
        label.setText("Ready.");

        add(label);
    }
}

我希望它是一个 UI 应用程序,因此无论是在启动时自动运行还是手动运行,它的屏幕都应该可见。如果我需要做一些事情以使其按预期工作,请指导我,我是 BlackBerry 开发的新手。 我正在以下环境中开发;

  • BlackBerry JDE Eclipse 插件 1.5.0
  • 黑莓操作系统 4.5

【问题讨论】:

    标签: blackberry java-me blackberry-jde


    【解决方案1】:

    自动启动应用程序在操作系统完成启动之前运行,因此不支持用户界面。我怀疑您的应用程序正在启动,但在某些 UI 调用上失败。编写要自动运行并从主屏幕运行的应用程序的文档化方法是为自动运行提供备用入口点,并使用参数告诉程序它已自动运行。然后使用 API 等待操作系统为 UI 应用程序做好准备。

    public class AppClass extends UiApplication {
        public static void main(String[] args) {
    
            if (args.length > 0 && args[0].equals("auto-run")) {
                // auto start, wait for OS
                while (ApplicationManager.getApplicationManager().inStartup()) {
                   Thread.sleep(10000);
                }
    
                /*
                ** Do auto-run UI stuff here
                */
            } else {
                AppClass theApp = new AppClass();
                theApp.enterEventDispatcher();
            }
        }
    
        public AppClass() {
            pushScreen(new AppScreen());
        }
    }
    

    【讨论】:

    • 谢谢先生。让我试试看。
    【解决方案2】:

    从 AppScreen 类的构造函数调用 getApplication().requestForeground();,以便您的屏幕可见。

    public final class AppScreen extends MainScreen {
    
        private LabelField  label;
    
        public AppScreen() {
            setTitle("AppTitle");
    
            label = new LabelField();
            label.setText("Ready.");
    
            add(label);
    
            getApplication().requestForeground();
        }
    }
    

    一旦应用在后台运行,我们必须明确地将其带到前台以显示 UI 元素,这就是我们在这里所做的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-02
      • 1970-01-01
      • 1970-01-01
      • 2011-09-13
      • 2023-01-29
      • 1970-01-01
      • 2011-02-15
      • 1970-01-01
      相关资源
      最近更新 更多