Starting the sample application in the background

You can use the Push Service APIs to start running your application when a push message arrives, and to continue running it in the background. This saves valuable device resources because your application doesn’t have to be running all the time to receive push messages.

The sample application calls the launchApplicationOnPush() function with a value of true. This call registers the application so that it starts running in the background if it isn't already running when a push message arrives. If you don't want to register your application so that it starts running in the background when a push message arrives, you can call launchApplicationOnPush() with a value of false. The push messages that arrive when the value is false are delivered only if your application is running when the messages arrive.

PushCapture.prototype.successCreatePushService = function(service) {      
 .
 .
 .
sample.pushcapture.pushService.launchApplicationOnPush(
       sample.pushcapture.launchapp, 
       sample.pushcapture.launchApplicationCallback);
 };

The launchApplicationCallback() callback function shows the error handling if the launch operation fails, and the error messages that you can use for debugging. In your application, you might want to handle the errors differently. For example, you might want to retry an operation first before displaying an error message. The API Reference lists the possible actions that you can take for each error constant. The API Reference also tells you which error codes apply to which function calls.

  if (result == blackberry.push.PushService.SUCCESS) {
       // Successfully registered to launch
       .
       .
       .
  } else {             
       .
       .
       .
              
       if (result == blackberry.push.PushService.INTERNAL_ERROR) {
             alert("Error: An internal error occurred while calling 
             launchApplicationOnPush. " + "Try restarting the 
             application.");
       } else if (result == blackberry.push.PushService.
                             CREATE_SESSION_NOT_DONE) {
             alert("Error: Called launchApplicationOnPush without an " +
             "existing session. It usually means a programming error.");
       } else {
             alert("Error: Received error code (" + result + ") after "
             + "calling launchApplicationOnPush.");            
       }
  }
};

Last modified: 2014-10-09



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus