The BlackBerry Mobile Data Service is capable of pushing data to a third-party application so that data is always available to the user. There are two common scenarios in which a push connection would be opened[1]:

  • when an application runs
  • when the device starts and runs in the background
//run method from with a thread
public void run() {
     //For Background Listener threads it is import to add the delay
     //If the application starts and displays the “Allow Connection” dialogue
     //Before the home screen is available it’s possible to cause a UI lock
     while(RadioInfo.getSignalLevel()==RadioInfor.LEVEL_NO_COVERAGE)(
          try {
               Thread sleep(1000);
          } catch( Exception e ) {}
     }
     //Just add an extra wait to ensure the device is fully up and running
     //the user is looking at the home screen
     try {
          Thread sleep(3000);
     } catch( Exception e ) {}

     StreamConnection stream = null;
     InputStream input = null;

     try {
          for(;;){
               try {
                    Thread.sleep(1000);
                    System.out.printIn(‘eclBackgroundThread--ThreadRunning (just to be sure)”);
               } catch( Exception e ) {}
          synchronized(this) {
               //synchronize here so that we don’t end up creating a connection that is never closed
               //The URL will be http://: where  is the value that the push server also                needs
               //to use to post data
               _notify = (StreamConnectionNotifier)Connector open(URL);
               _connectionOpened = true;
          }

          //NOTE: the following will block until data is received
          stream = _notify acceptAndOpen();
          input = stream.openInputStream();

          //Read the received data in from the stream and process it accordingly
     } catch (IOException ioex) {}
}



[1] http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/796557/800451/800662/How_To_-_Open_a_push_listener_connection.html?nodeid=1033505&vernum=0