Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Detect system availability on startup

by BlackBerry Development Advisor ‎02-16-2010 03:25 PM - edited ‎09-16-2010 02:50 PM (3,499 Views)

Summary

 

This article applies to the following:

  • Blackberry® Device Software 4.0 and later

Details

 

One of the possible configurations for applications on BlackBerry smartphones is to set up your application to run on startup which indicates that the application will be executed during BlackBerry smartphone initialization, before the BlackBerry smartphone user is allowed to unlock or use the BlackBerry smartphone. For more information on how to configure your application to run on startup, see this article.

 

One of the common challenges when running on startup is knowing when the system itself is available and ready. This is important in certain scenarios where the application must run on startup but cannot perform its actions until the system is ready. For example, if your application needs to access a resource that will prompt the BlackBerry smartphone user for permission (e.g. opening an http connection, accessing the address book, etc.), the application permissions engine will not be able to display a dialog until the system is ready.

 

The best way to ensure that the system is available and ready is to leverage the ApplicationManager class with its inStartup method along with using a system listener and its powerUp method. Sample code is included below as an example on how you can detect when the system is available and ready.

 

 

public static void main( String[] args ) {
// Perform additional work as part of main method if necessary.
if( ApplicationManager.getApplicationManager().inStartup() ) {
// Add a system listener to detect when system is ready and available.
applicationInstance.addSystemListener( applicationInstance );
} else {
// System is already ready and available so perform your start up work
now.
// Note that this work must be completed using invokeLater because the
// application has not yet entered the event dispatcher.
applicationInstance.doStartupWorkLater();
}
// Enter the event dispatcher.
applicationInstance.enterEventDispatcher();
}
/**
* Implementation of the powerUp method for the SystemListener interface
*
*/
public void powerUp()
{
applicationInstance.removeSystemListener( this );
doStartupWork();
}
/**
* Perform the start up work on a new Runnable using the
* invokeLater construct to ensure that it is executed
* after the event thread has been created.
*
*/
private void doStartupWorkLater()
{
applicationInstance.invokeLater( new Runnable() {
public void run() {
doStartupWork();
}
} );
}
/**
* Your private method for performing your startup work.
*
*/
private void doStartupWork()
{
// Perform your start up activities here!
}

 

 

 

Contributors
Users Online
Currently online: 8 members 2,811 guests
Please welcome our newest community members: