App Life Cycle
The life cycle of an app refers to the states that an app can move through while it runs.
To create a fully functional app that runs on a BlackBerry 10 device, you must understand the various states that an app passes through from the time the app is launched up to the point where it is terminated. Knowledge of these states will help you to write code that appropriately responds to transitions from one state to another.
In its simplest form, the life cycle of your app can be divided into three stages: it starts, runs for a period of time, and then ends. The BlackBerry 10 OS is a multi-threaded, multi-tasking platform that runs multiple apps at the same time. When your app is running in the foreground, it is active. However, it can be interrupted when another app opens and replaces yours as the active app. When your foreground app is no longer active, it can be pushed to the background without fully terminating. A background app can be reactivated at any time. The app can also be closed by the user or, in some circumstances, terminated by the system, without ever becoming active or being acted on by the user. Therefore, without managing these transitions, the app can behave in a way that was not intended.
As you can see from the diagram above, there are many states and the application is able to transition back and forth from one state to another. These transitions comprise your app's life cycle so your code needs to reflect different behaviors depending on the various types of transitions. When an app makes its transition from one stage of the life cycle to another, the BlackBerry 10 OS notifies the app using events. The events that an app receives can vary depending on the way the user configures the settings on the device.
When the device is in critical condition, the OS may terminate your app without the user’s manual instruction to do so. For example, when the device is out of battery power and shuts down, it closes all open apps. Alternatively, if the device is running many memory-intensive apps, a low-memory situation may occur. The OS handles low-memory conditions by closing idle background apps to reclaim memory resources.
From simple transitions such as minimizing and maximizing the app to abnormal ones such as automatic termination, you must manage all possible transitions to produce a good BlackBerry 10 app.
Last modified: 2013-12-21