Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BlackBerry App: Screen Not Showing Up In Auto Run Mode

I am trying to create a background app which will run at system startup. When I run it manually (from the ribbon), the screen appears but when I run the app after making it a startup app (Auto-run on startup option in descriptor), nothing appears on screen. I am trying the following code;

public class AppClass extends UiApplication {

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

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

And this is the screen class;

public final class AppScreen extends MainScreen {

    private LabelField  label;

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

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

        add(label);
    }
}

I am expecting that its a UI app so its screen should be visible no matter if is auto-run at startup or run manually. If I need to do something to make it work as expected, please guide me about it, I am new to BlackBerry development. I am developing in the following environment;

  • BlackBerry JDE Eclipse Plugin 1.5.0
  • BlackBerry OS 4.5
like image 519
Mudassir Avatar asked Jun 27 '12 04:06

Mudassir


1 Answers

Auto start applications are run before the OS has completed booting so there isn't any support for the user interface. I suspect your application is being launched but failing on some UI call. The documented way to write an application that is to auto run and run from the home screen is to provide an alternated entry point for the auto run with arguments that tell the program it has been auto run. Then use the API to wait until the OS is ready for UI applications.

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());
    }
}
like image 162
Richard Avatar answered Sep 29 '22 08:09

Richard