Search code examples
blackberryjava-meblackberry-jde

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

Solution

  • Call getApplication().requestForeground(); from the constructor of your AppScreen class so that your screen will be visible.

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

    Once the app is running in background, we have to bring it to foreground explicitly to show UI element and that is what we are doing here.