Various Transitions

An application undergoes various transitions from the time it is launched to the time it is terminated. You need to understand and manage the various transitions to fully utilize the application life cycle.

While it is important to understand each of the states and manage them individually, the essence of the app life cycle is that the apps transition from one state to another and it is extremely important to manage the transitions well to create a good app. For example, a user may be playing a game that didn’t implement its various state transitions correctly. In the middle of an important stage in the game, the user gets an e-mail and goes to switch apps, while the improperly implemented game does not pause. Furthermore, as the developer assumed that the user would save the user’s accomplishments before putting the app into the background, all of the accomplishments are lost as the game ends while the user is reading the e-mails. When a state transition is not implemented properly, such things can occur, degrading the user experience.

The BlackBerry 10 OS notifies apps of their changes in states with the use of events. These events notify the app of state changes and your app should respond to these state changes accordingly. For example, when the app is pushed from its full screen state to a thumbnail state, the app receives this information through the events such as NAVIGATOR_WINDOW_THUMBNAIL and NAVIGATOR_WINDOW_INACTIVE. You must determine how each of these events will affect your app in your code to be able to fully manage the transitions between different stages of the app life cycle.

The following code example demonstrates how your app receives transition events:

static void handle_events(){
    // Request and process available BPS events
    for(;;) {
        bps_event_t *event = NULL;
        if (BPS_SUCCESS != bps_get_event(&event, 0)) {
            fprintf(stderr, "bps_get_event failed\n");
            break;
        }
        
        if (event) {
            int domain = bps_event_get_domain(event);
            
            if (domain == screen_get_domain()) {
                handleScreenEvent(event);
            } else if (domain == navigator_get_domain()) {
                handleNavigatorEvent(event);
            }
        } else {
            break;
        }
    }
}
        
static void handleNavigatorEvent(bps_event_t *event) {
    switch (bps_event_get_code(event)) {
        case NAVIGATOR_WINDOW_INACTIVE:
        
        //Various actions needed to be performed for each switch case.
        
        break;
    }
}