Starting the sample application in the background

After the sample application successfully creates a push session, it can call registerToLaunch() so that the application can start running in the background if it isn't already running when a push message arrives. The registerToLaunch() function is called in the createSessionSuccess() event handler that handles the PushServiceEvent of type CREATE_SESSION_SUCCESS. In your application, if you try to call registerToLaunch() before you successfully create a push session, you'll get an error on the register to launch operation.

/**
* Actions to perform when creating a push session is successful. 
* @param e a create session success event
*/
private function createSessionSuccess(e:PushServiceEvent):void
{      
    .
    .
    .                     
    if (shouldRegisterToLaunch) {
        pushNotificationService.registerToLaunch();
    } else if (shouldUnregisterFromLaunch) {
        pushNotificationService.unregisterFromLaunch();
    } else {
        dialogSuccess("Configuration", "Configuration was
           saved.");                                     
    }
}

The register to launch flag is saved between application restarts only if you create a push channel or if the channel remains active. If you don't create a channel or the create channel operation fails, the register to launch flag isn't saved. When a channel is destroyed, the flag is lost.

If you don't want to start your application when a push message arrives, call unregisterFromLaunch(). The push messages that arrive after you call unregisterFromLaunch() are delivered only if your application is running when the messages arrive. Additionally, the default starting behavior for your application is unregisterFromLaunch(), so you would call unregisterFromLaunch() only if you called registerToLaunch() previously. For more information about registerToLaunch() and unregisterFromLaunch(), see the API Reference.

comments powered by Disqus