Manage apps through the application life cycle

The life cycle of an application refers to the stages that an application can move through, from the time it is invoked until it is terminated. It is important to understand the implications that various states and transitions of the life cycle can have on your application so that you can respond to them appropriately in your code.

The life cycle of your application normally has three stages: it starts, runs for a period of time, and then ends. The BlackBerry 10 OS is a multi-threaded, multi-tasking platform so it can run multiple applications at the same time. While your application is running in the foreground, it is active. However, it can be interrupted when another application opens and replaces yours as the active application. If your application loses focus, it is not terminated but it may be deactivated and pushed to the background. A background application can reactivated—returned to the foreground—at any time, or may be closed by the user. The application may be terminated by the system, without ever becoming active again.

When an application needs to move from one stage of the life cycle to another, the BlackBerry 10 OS notifies the application using an event. The events that an application receives can vary if a user changes the application behavior setting on the device.

During the application life cycle, other events might cause your application to terminate prematurely (that is, before the user has closed it). For example, when the battery drains, the device shuts down and closes all open applications. Alternatively, if a user has too many applications open, it could create a low memory situation. The BlackBerry 10 OS handles low memory conditions by closing idle background applications so it can reclaim memory resources.

For more information on responding to system events, see the BlackBerry Platform Services Library Reference.