我正在尝试创建一个将在系统启动时运行的后台应用程序。当我手动(从功能区)运行它时,屏幕会出现,但是当我在将其设为启动应用程序(描述符中的启动时自动运行选项)后运行该应用程序时,屏幕上没有任何显示。我正在尝试以下代码;
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 应用程序,因此无论是在启动时自动运行还是手动运行,它的屏幕都应该可见。如果我需要做一些事情以使其按预期工作,请指导我,我是黑莓开发的新手。
我在以下环境中开发;
最佳答案
自动启动应用程序在操作系统完成启动之前运行,因此不支持用户界面。我怀疑您的应用程序正在启动,但在某些 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());
}
}
关于黑莓应用程序 : Screen Not Showing Up In Auto Run Mode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11219341/