Display a GUI when the BlackBerry device starts up

by Retired ‎02-16-2010 12:41 PM - edited ‎09-16-2010 02:37 PM (3,492 Views)

Summary

 

This article applies to the following:

  • BlackBerry® Java™ Development Environment (JDE) 4.0 and later

Description

 

An auto-start application that pushes a screen upon start-up must wait for the Graphical User Interface (GUI) process to finish loading when a BlackBerry device is rebooted or restarted. To do this, you can check the ApplicationManager.inStartup() and delay the push of the screen. The inStartup() method will return true if the device is in a start-up process, otherwise it will be false. The following code sample creates outlines on how to use the ApplicationManager.inStartup() method:

 

 

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;

public class SampleApplication extends UiApplication
{
    private Thread _thread;

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

    public SampleApplication()
    {
        _thread = new Thread(new checkRequest());
        _thread.start();
    }

    public class checkRequest extends Thread
    {
        public void run()
        {
            // Creates an instance of the system’s application manager.

            ApplicationManager myApp =
                ApplicationManager.getApplicationManager();

            while(myApp.inStartup())
            {
                try
                {
                    _thread.sleep(2000);
                } catch(Exception e) {
                    // Catch Exception
                }
            }

            UiApplication.getUiApplication().invokeLater(new Runnable()
            {
                public void run()
                {
                    pushScreen(new MyMainScreen());
                }
            });

            UiApplication.getUiApplication().requestForeground();
        }
    }

    final class MyMainScreen extends MainScreen
    {
        public MyMainScreen()
        {
            super();
            BasicEditField field1 = new BasicEditField("Test:","");
            add(field1);
        }
    }
}