BlackBerry app: screen does not appear in auto start mode

I am trying to create a background application that will start when the system starts. When I start it manually (from the tape), a screen appears, but when I start the application after it starts the application (autostart when it starts in the handle), nothing appears on the screen. I am trying to execute 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 expect this application to be a UI, so its screen should be visible regardless of whether autorun is performed at startup or manually started. If I need to do something to make it work properly, tell me about it, I'm new to BlackBerry development. I am developing in the following environment:

  • BlackBerry JDE Eclipse Plugin 1.5.0
  • BlackBerry OS 4.5
+6
source share
2 answers

Call getApplication (). requestForeground (); from the constructor of your AppScreen class so that your screen is 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 application is running in the background, we must explicitly bring it to the forefront to show the interface element, and this is what we are doing here.

+2
source

Auto start applications start before the OS finishes loading, so there is no support for the user interface. I suspect that your application is starting, but does not work on some invocation of the user interface. The documented way to write an application that should automatically start and start from the main screen is to provide an alternative entry point for automatic launch with arguments that indicate that the program was automatically launched. Then use the API to wait for the OS to be ready for the user interface 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()); } } 
+5
source

Source: https://habr.com/ru/post/919088/


All Articles