Owners of Android smartphones often encounter a situation where an application that you just minimized suddenly restarts when you return to it. Instead of continuing where you left off, the app shows the start screen or requires you to log in again. This phenomenon causes irritation and is mistakenly perceived by many users as a “cooked optimization” or a system bug. In fact, behind this is a fundamental operating system resource management mechanism called Background Activity Preemption. The Android system is designed in such a way that it always strives to provide maximum performance for the currently active application that is in the foreground. If there is not enough random access memory (RAM), displacing background Activities.

The Android system is designed in such a way that it always strives to provide maximum performance for the currently active application that is in the foreground. If the random access memory (RAM) becomes insufficient, ActivityManager it begins to forcefully terminate processes in the background. This is done in order to free up resources for the task you are using right now. Understanding exactly how this process works will help you set up your device and avoid losing data in unfinished tasks.

In this article, we will take a detailed look at the architectural features of the application lifecycle, the role of the task stack, and the impact of RAM on the stability of multitasking. You will learn what factors provoke premature closing of apps and how you can influence this process without obtaining root access.

Memory management architecture in Android

The operation of any modern mobile operating system is based on the principle of allocating limited resources. Unlike desktop computers, where the amount of RAM can amount to tens of gigabytes, in smartphones this resource is strictly limited. When you run an application, the system creates a separate process for it and allocates a specific memory pool. This process is managed by the Linux kernel on which Android is based.

The key component here is Low Memory Killer (LMK) the kernel mechanism that monitors available RAM. Once free memory drops below a certain threshold, LMK starts killing processes according to their priority. Applications that you minimize become background processes and their priority is automatically reduced. If you open a heavy game or camera, the system will instantly free up space by closing background browser tabs or instant messengers.

It is important to understand that Android does not keep applications in the background forever. There is a concept LRU cache (Least Recently Used - least recently used). The system maintains a list of processes sorted by the time they were last accessed. When memory is required, the first to go under the knife are precisely those applications that the user has not accessed for the longest time. This ensures that active tasks will not slow down due to lack of resources.

⚠️ Attention: Many users mistakenly believe that constantly clearing memory through third-party “accelerators” helps keep applications in the background. In fact, forcibly closing processes frees up memory only for a short time, after which the system spends additional CPU resources on re-launching these applications, which leads to increased battery consumption.

📊 How often do you restart minimized applications?
Constantly, every 5 minutes
Sometimes, when launching heavy games
Rarely, only if I don’t use a watch
Never, everything always hangs in the background

Activity life cycle and process states

To understand the reasons preemption, you need to understand what states an application component can be in. An Activity is one interface screen with which the user interacts. The life cycle of an Activity includes several key phases that determine how “important” the system considers a given process.

When you are inside an application, its Activity is in the state RESUMED. This is the highest priority: the system will under no circumstances kill such a process, except in the event of a critical failure of the device itself. As soon as you press the Home button or switch to another application, the current Activity switches to STOPPEDstate. At this point, it is still stored in memory, but no longer has input focus and is not drawn on the screen.

If the system experiences an acute shortage of memory, it begins to terminate processes in the state STOPPED. However, before this happens, the application has a chance to save its state. The onSaveInstanceState() method allows developers to write current data (for example, text in an input field or scroll position) into a special Bundle. When restarted, the system tries to restore the Activity from this saved state, creating the illusion of continuous operation.

Technical details of the CACHED state

Starting with Android 8.0 (Oreo), a new process state has appeared - CACHED. In this state, the application process does not execute any code and holds a minimal amount of memory. Such processes are the first candidates to be killed when there are insufficient resources, even earlier than processes in the STOPPED state, if they do not contain active services.

Developers must competently handle the situation when an Activity has been killed by the system. If you return to the application and it starts again, this means that the process was completely destroyed and the restoration occurred from the saved data or the main screen simply opened. Incorrect implementation of the recovery logic often leads to users seeing their progress reset.

Factors influencing the aggressiveness of displacement

Why do ten applications hang in the background for days on one smartphone, while on another they close a minute after being minimized? The answer lies in the combination of hardware limitations and software settings of the manufacturer. The amount of RAM is the main, but not the only factor. Modern shells from manufacturers, such as Xiaomi, Samsung or Oppo, often have their own, more aggressive energy saving algorithms. They can forcefully stop background processes even if there is still free memory to extend battery life. This is especially true for budget devices with small batteries, where every milliamp counts.

Modern shells from manufacturers such as MIUI from Xiaomi, OneUI from Samsung or ColorOS from Oppo often have their own, more aggressive power saving algorithms. They can forcefully stop background processes even if there is still free memory to extend battery life. This is especially true for budget devices with small batteries, where every milliamp counts.

The number of running services and widgets also affects. If navigation, music player and mail synchronization are running in the background, they take up a significant portion of RAM. In such a situation, there is simply no place left for a regular browser or social network. The system is guided by the rule: it is better to close one unnecessary application than to allow freezes in the interface or a drop in FPS in the game.

Influence factor Mechanism of influence Result for the user
Amount of RAM (RAM) Defines the LRU cache limit The more GB, the more applications remain in the background
Energy saving settings Forced stop of background services Applications close even if there is free memory
Heavy active application Requires allocation of a large contiguous memory block Instant eviction of all background tasks
Android version Changes in LMK algorithms and memory management Newer versions of Android tend to clean the background more aggressively
💡

If you are using a smartphone with 4 GB of RAM or less, try not to keep more than 3-4 heavy applications open at the same time. For devices with 8-12 GB of memory, this limitation is almost imperceptible in everyday use.

The role of the developer in preventing restarts

Responsibility for the stable operation of the application in low memory conditions lies not only with the system, but also with the software creators. Competent code architecture allows you to minimize the consequences of Activity preemption. If an application takes up too much memory due to memory leaks, it will become the first victim of the system.

Developers use special annotations and configurations in the file AndroidManifest.xmlto tell the system the importance of the process. For example, the attribute android:persistableMode or starting the service in foreground mode (with a visible notification) increases the priority of the process. Messengers and music players use this trick so that they are not killed when minimized.

In addition, there is a mechanism Process Statethat the application can request from the system. Recent versions of Android have introduced APIs that allow you to request an exception to power saving rules for mission-critical tasks. However, Google strictly moderates the use of such privileges to ensure that software developers do not abuse them to the detriment of the autonomy of the user's device.

⚠️ Attention: If you are a developer, never rely on your application to remain in memory. Always implement state saving in the method onSaveInstanceState and use a ViewModel to store data that survives the re-creation of the Activity.

How can a user configure applications to remain in the background

Although we cannot completely disable the preemption mechanism without rebuilding the system kernel, there are legal ways “train” your smartphone not to close the necessary apps. These settings are hidden deep in the menu and are often ignored by ordinary users.

The first step is to disable battery optimization for specific applications. To do this, go to Settings → Applications → [Select an application] → Battery and select mode No restrictions (or “Do not limit”). This will prevent the system from killing the process of this application in the background to save power, although if there is a critical lack of RAM, it can still be closed.

The second method is to pin the application to the RAM memory through the multitasking menu. Open the list of running applications (Square button or swipe from below), find the desired app, click on its icon or hold your finger on the application card. In the menu that appears, select the option Block or click on the lock icon. Blocked applications are usually ignored by clearing the memory when you click the “Close All” button.

☑️ Setting an exclusion from power saving

Done: 0 / 5

It is worth noting that on different firmware these settings may be called in different ways. For Xiaomi it is “Autostart” and “No restrictions” in the battery menu, for Samsung it is “Sleep applications” and “Non-sleeping applications”. Interfaces are updated frequently, so the search logic may change slightly.

⚠️ Attention: Details of menu location and item names may vary depending on the version of Android and the manufacturer's shell (MIUI, OneUI, ColorOS, etc.). Always check the official manual for your specific smartphone model if you cannot find the item you need.

💡

Pinning an application to the multitasking menu and disabling battery optimization are two of the most effective ways to prevent the system from closing it in the background.

Diagnostics and advanced analysis methods

For those who want to deeply understand what exactly is happening with the memory of their device, there are developer tools. They allow you to see the real picture of resource distribution in real time, without embellishment from beautiful interface animations.

You can activate the developer menu by clicking 7 times on the item Build number in the section About the phone. After the new menu appears in the settings, find the section Running services or Memory statistics. Here you will see a list of all active processes, how much RAM they take up and how long they have been running in the background. This will clearly show which application is “eating up” all the memory.

The option is also useful Do not save actions (Don't keep activities) in the developer menu. If you enable it, the system will destroy the Activity as soon as the user leaves the screen. This is a useful tool for testing, but in everyday life you cannot turn it on, as this will make using the smartphone impossible - each switch will be tantamount to restarting the application.

adb shell dumpsys meminfo

For a deeper analysis, you can connect the smartphone to the computer and use the ADB command shown above. It will display a detailed report on the memory consumption of each process, including details by memory type (Native, Dalvik, Graphics). This is a professional tool that helps identify memory leaks in specific applications.

What does OOM Killer mean?

OOM (Out Of Memory) Killer is a Linux kernel process that is triggered when the system has completely exhausted the available memory and cannot allocate a new block even for critical tasks. It forcibly terminates processes with the lowest priority to save the system from a complete freeze (kernel panic).

Frequently asked questions (FAQ)

Why does the application close even if I have 8 GB of RAM?

Memory size is not the only factor. Aggressive manufacturer power saving settings, background services of other applications, or optimizations of the system itself can force processes to close. Check the battery settings for a specific application and remove restrictions.

Is it harmful to constantly keep many applications in the background?

In terms of hardware wear, no, modern RAM is designed for constant writing. However, background processes consume processor and radio power, which reduces battery life. The balance between multitasking and autonomy can be adjusted individually.

How to find out which application is eating up memory the most?

Use the built-in Memory Statistics tool in the developer menu or third-party utilities like Simple System Monitor. They will show the rating of applications by RAM consumption over the last hour or day.

Is it possible to completely disable Activity preemption?

Without root access and modification of system files (kernel) - it is impossible. This is the basic working mechanism of Android. You can only increase the priority of specific applications so that they are closed last.

Why did applications begin to close more often after updating Android?

New versions of Android often tighten background policies for the sake of security and energy saving. It is also possible that the updated application began to consume more resources than before due to new features or unoptimized code.