Indeed, despite the fact that the translation is posted on the official website, it is made extremely unreadable. Moreover, in general, to understand the meaning of the concepts of the foreground process and the visible process is quite problematic. I will try to present my version of the translation of this part of the documentation with a few additions.
The foreground process is the process required for the user's current activity. The various components of an application (Activity, Service, BroadcastReceiver) can cause the containing process to be considered as a foreground process. A process is considered a foreground process if any of the following conditions are met:
- it contains the Activity with which the user interacts (the Activity onResume () method is called, that is, the Activity is apparently in the foreground);
- it contains the currently running BroadcastReceiver, i.e. the onReceive () method is executed. The receiver of broadcast messages is active only during the execution of this method. The process currently performed by BroadcastReceiver, that is, the currently running code in the onReceive () callback method is considered by the system to be a priority process and will be saved, except in cases of critical memory shortage in the system. When the program returns from the onReceive () method, the receiver becomes inactive and the system assumes the operation of the BroadcastReceiver object is over. A process with an active broadcast receiver is protected from being destroyed by the system. However, a process containing inactive components can be destroyed by the system at any time when the memory it consumes is needed by other processes;
- it contains a Service, which performs one of the lifecycle callbacks (onCreate (), onStart () or onDestroy ()). Despite the fact that there is no onStart () method in the Service, in general it is a question of how it relates to the foreground process from the moment of its creation until destruction. Attention! An exception is the launch of Service using the Service.startForeground () method, in which case it refers to visible processes.
Usually, only a few foreground processes are running at a time. They are destroyed only as a last resort, if there is so little memory left that they cannot continue to work together. Usually, at this moment, the device has reached the state of memory pagination, so in order for the user interface to respond to user actions, it is necessary to delete some foreground processes. It should be noted that, in theory, all visible processes should be completed by this point.
Visible processes are processes that do not contain application components that would relate it to the foreground process, but which can affect the display on the screen. A process is considered visible if any of the following conditions is true:
- it contains an Activity that is not in the foreground, but visible to the user (the onPause () method is called). For example, this may occur if a dialog was launched from the Activity that allows you to see the Activity behind it;
- it contains the Service, which is started using the Service.startForeground () method (that is, it is a service that the user is actively aware of). A service started in this way should display a notification in the status bar, which is located under the “Permanent” heading. This means that the notification cannot be deleted until the service is stopped or deleted. And here, when translating, a few "confuses" the method by which the service is called (startForeground ()). its name directly echoes the process name - the foreground process. But despite this coincidence, a service launched with the help of Service.startForeground () still refers to visible processes;
- it contains the service that the system uses for a specific function that the user knows about, such as live wallpaper, input method, etc.
Visible processes are considered to be extremely important, and they are deleted only if it is necessary to keep the work of all the foreground processes.