Android Processes
Android is a multi user, multitasking system that can run multiple applications at the same time and let the user switch between applications. The Linux kernel handles the multitasking, and application execution is based on Linux processes.
When an application starts, the Android system starts a new Linux process and every Android application runs in its own Linux process with a single thread of execution. This process is created for the application and will remain running until it is no longer needed and the system needs to reclaim its memory for use by other applications.
An unusual and fundamental feature of Android is that an application process’s lifetime is not directly controlled by the application itself. Instead, it is determined by the system through a combination of the parts of the application that the system knows are running, how important these things are to the user, and how much overall memory is available in the system.
It is important that application developers understand how different application components (in particular Activity, Service, and BroadcastReceiver) impact the lifetime of the application’s process. Not using these components correctly can result in the system killing the application’s process while it is doing important work.
Application termination:
A process is created at the start of the application and finishes when the system wants to free up resources. Because a user may request an application at any later time, the runtime avoids destroying all its resources until the number of live applications leads to an actual shortage of resources across the system. Hence, an application isn’t automatically terminated even when all of its components have been destroyed. When the system is low on resources, it’s up to the runtime to decide which process should be killed. To make this decision, the system imposes a ranking on each process depending on the application’s visibility and the components that are currently executing. In the following ranking, the bottom-ranked processes are forced to quit before the higher-ranked ones.
Get Nithin Raja’s stories in your inbox
Join Medium for free to get updates from this writer.
There are five levels in the importance hierarchy:
Foreground Process:
Application has a visible component in front, Service is bound to an Activity in front in a remote process, or BroadcastReceiver is running.
Visible Process:
Application has a visible component but is partly obscured.
Service Process:
Service is executing in the background and is not tied to a visible component.
Background Process:
A nonvisible Activity . This is the process level that contains most applications.
Empty Process:
A process without active components. Empty processes are kept around to improve startup times, but they are the first to be terminated when the system reclaims resources.
In practice, the ranking system ensures that no visible applications will be terminated by the platform when it runs out of resources.





