In Android: When the system is running low on memory, the Android system will kill some less important processes based on the priority of the process, and the lower priority kills first. The process priority is from high to low as follows.
Foreground process
- In the activity that is interacting with the user
- Service bound to the foreground activity
- Service that called the Startforeground () method
- Executing service for OnCreate (), OnStart (), OnDestroy method.
- The process contains the broadcastreceiver that is executing the onreceive () method.
There are not many foreground processes in the system, and generally the foreground process is not killed because of insufficient memory. Except in special cases. Killing a process is not an option when memory is low to ensure that all foreground processes are running at the same time.
Visual process
- Activity that is in the foreground but still visible (for example, call OnPause () and not yet call OnStop (). Typically, when you run the activity, the dialog box pops up (dialog, etc.), but the activity is still visible, although it is not the foreground activity.
- The service to which activity is bound is visible. (Service bound by activity in case of appeal)
The visual process is generally not killed by the system unless it is necessary to ensure that the foreground process is running.
Service process
- Service that has been started
Background process
- Invisible activity (activity after calling OnStop ())
The background process does not affect the user's experience, in order to ensure that the foreground process, visual process, the running of the service process, the system may at any time kill a background process. When a properly implemented lifecycle activity is killed in the background, the previous run state is restored if the user restarts.
Empty process
- Any process that is not active
The system kills empty processes, but this does not affect them. The existence of an empty process is nothing more than a cache, so that it can be started faster next time.
Reference articles
Https://github.com/LRH1993/android_interview/blob/master/android/basis/process-priority.md
Android Interview Collection catalog Android process priority