App Life Cycle
The life cycle of an app refers to the states that an app can move through while it runs.
These states include from the time the app is launched up to the point where it is terminated. To create a fully functional app that runs on a BlackBerry 10 device, it is important for you to understand the various states that an app passes through during its life cycle. These understandings 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 it wasn’t intended to behave.High-level Diagram of App Life Cycle
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 are what causes the life cycle to be so your code needs to reflect different behaviors of your app 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 and shuts down, it force closes all open apps. Alternatively, if the device is running many memory-intensive apps, a low-memory situation may occur. As such, 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 have to, as a developer, manage all possible cases as your app moves from one stage to another to produce a good BlackBerry 10 app.