When the Android system memory is insufficient, the problem of the assembly recycling sequence

When the Android system runs out of memory, it is necessary to remove old or unnecessary applications. As described in the previous Activity life cycle, the decision to remove is determined by the state of the application. Generally speaking, When an application needs to be removed, the system will sort it, and then remove it from the least important, the following is the order of consideration when removing:

 1. The first to be removed is the Empty Process (empty process):

Empty process refers to those processes that are not bound to Activity, nor to any application components (such as Service or IntentReceiver). These empty processes must be the first ones to be considered for removal by the system.


       2. The second consideration to be removed is Background Activity.
Background Activity refers to the situation that this activity cannot be seen by the user, indicating that the Activity has been in the stop state, and it is safe for the system to remove these activities. Usually there are Multiple Background Activities are running at the same time, these activities are stored in an LRU (least recently used) list, the system can judge which activities can be removed and which one should be removed first according to the LRU list.

 

3. The third place to be removed is Service Process.
In Android applications, there is a category without UI (android.app.Service), which is called Service. Service Process is usually started by startService(). To put it simply, Service belongs to the background program. Through the background program, we can make some functions that do not require UI, such as: playing music in the background, uploading or downloading files, etc. The system usually protects it, unless it is really No memory is available.

 

4. Then it is the turn of Visible Activity / Visible Process:
Visible Process is a Visible process, but it is not displayed at the top (when onPause is used). For example, when a new dialog Activity appears, the original Activity It is still visible, it is still considered important by the system, and it is usually not removed. But if it has to be removed, it is already in a relatively safe position because it is in the Paused state.

 

5. The last thing to be removed is Foreground Activity:
Foreground is an Activity that interacts with the user at the top of the screen, and it has the highest priority. In principle, it will be the last program to be removed, unless this Activity needs The memory size has exceeded what the system can give. The reason why the system removes these programs is to prevent the user page from stopping responding.

 

Because the lifecycle of Android applications is not directly controlled by the program itself, but managed by the system platform. So for developers, it is necessary to understand the Lifecycle of different components Activity, Serivce and IntentReceiver. Remember: if the components are used improperly , although an important process is in progress, it may still be actively removed by the system 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326788220&siteId=291194637