How to add an application to the cleaning exceptions on Xiaomi: protect data from auto-cleaning

Xiaomi MIUI-based smartphones are known for aggressive memory optimization: the system automatically closes background processes and clears the cache of applications to save battery power and free RAM. However, this feature often deletes data from important programs such as messengers, navigators or games, which makes them longer to start, lose unsaved settings or even leave your account.

In this article, you will find the most current ways to protect applications from auto-cleaning on MIUI 12-15 (including HyperOS), and understand why some programs can still be closed by the system. We tested the instructions on the Redmi Note 12 Pro+, Xiaomi 13 Ultra and POCO F5 models – the methods work on all devices of the brand released after 2020.

Why Xiaomi is cleaning apps: the mechanism of auto-cleaning

The MIUI auto-cleaning function uses two key mechanisms:

  • πŸ”„ Cache Clearing: The system deletes temporary application files (for example, downloaded images in messengers or maps in navigators) if they have not been used for a long time.
  • ⚑ Battery optimization: background processes are paused or shut down to reduce charge consumption.
  • πŸ—‘οΈ Automatic Memory Cleanup: When RAM is lacking, the system forcibly closes applications, even if they are added to exceptions (but less often).

It is important to understand that adding exceptions does not guarantee 100% shutdown protection, it only reduces the probability. For example, if there is less than 200 MB of free memory left in the system, MIUI can ignore exceptions and force the background processes to be cleared.

Also, auto cleaning depends on the battery mode:

  • πŸ”‹ Balanced: Moderate optimization (recommended for most users).
  • 🌿 Charge savings: aggressive closing of background processes.
  • ⚑ Performance: Minimal optimization (but battery runs down faster).

⚠️ Note: On HyperOS devices (e.g. Xiaomi 14), the path to exception settings may be different. If you don't find Special Permissions, check the Apps section β†’ Application management β†’ Auto-start.

Method 1: Adding exceptions to security (MIUI 12–14)

This is the most reliable method for most devices, and the instructions are relevant for smartphones on MIUI 12-14, including Redmi 10/11, POCO X4/X5 and Xiaomi 12/13:

  1. Open the Security app (shield icon).
  2. Go to Optimization (or Acceleration on some firmware).
  3. Tap it on. βš™οΈ Settings in the upper right corner.
  4. Select the Cleanup Exceptions (or the Exclusion List).
  5. Click Add Apps and mark the desired programs.

Once added, the application will be protected from:

  • 🧹 Automatic Cache Cleanup When Pressed Clean Up in the Optimization Menu.
  • ⏸️ Forced background closure (but not 100% – see the restriction section).

Is the application open in the background (check the latest task menu)

Are the settings not reset during reboot

Is the cache saved (for example, maps in Google Maps)

Does not appear notification "Application optimized"-->

If the application is not listed, make sure it is installed in the main memory of the phone (not on the phone). SD-Also, some system programs (e.g. Google Play Services) cannot be added to the exceptions.

Method 2: Setup autostart and background activity

Even if the application is added to the cleaning exceptions, the system can block its background operation, and to avoid this, you need to enable auto-start and allow background activity:

  1. Go to Settings β†’ Applications β†’ Application Management.
  2. Select the desired application (for example, Telegram or Yandex.Navigator).
  3. Slip it on Permission.
  4. Turn on the switches: πŸ”„ Auto-Run (allows the application to start when the phone is turned on). πŸ“± Background activity (allows work in the background). πŸ”Œ No battery restrictions (disables optimization for this application).

πŸ’‘

If the permission list does not include Background Activity, try clearing the Security app cache (Settings β†’ Apps β†’ Security β†’ Storage β†’ Clear the cache) and restarting the phone.

On some firmware (e.g. MIUI 13 Global), the item No battery constraints may be called Battery Optimization β†’ No restrictions. If it is not, then the application is already excluded from optimization.

Method 3: Using ADB for deep optimization (for advanced)

If standard methods don’t help (for example, the application still closes), you can manually disable optimization via ADB. This method is suitable for advanced users and requires connecting the phone to a computer.

You'll need:

  • πŸ–₯️ Computer with installed ADB-Drivers (you can download from the Xiaomi website or through Android) SDK).
  • πŸ“± Included Debugging by USB on the phone (Settings) β†’ The phone. β†’ Version. MIUI β€” Tap 7 times, then return to the additional β†’ For developers).
  • πŸ”Œ USB-cable (preferably original).

Instructions:

  1. Connect the phone to the PC and confirm the debugging permission.
  2. Open the command line (Win + R β†’ cmd) and type:
adb shell dumpsys deviceidle whitelist +com.example.packet

Replace the exemplary package with a real application package (you can find it through the App Inspector or the APKMirror website). For example, for Telegram, the command will:

adb shell dumpsys deviceidle whitelist +org.telegram.messenger

To check the list of excluded applications, use:

adb shell dumpsys deviceidle whitelist

⚠️ Attention: Misuse of the right ADB Do not add system applications (e.g. com.miui.securitycenter) to the exceptions unless you understand the consequences.

How to find out the application package without third-party programs?
1. Install the file manager (e.g. Mi File Explorer). 2. Go to /data/app/ (root rights required) or use the command: adb shell pm list packages | grep "application name" 3. The packet name will be in com.company.app format (e.g. com.whatsapp for WhatsApp).

Limitations and nuances: why apps are still closed

Even after adding an exception, some applications may close, and here are the main reasons:

Problem.Reason.Decision
The application closes when the screen is blockedCharge Saving or Deep Optimization Mode EnabledSwitch to Balanced Mode in Settings β†’ Battery
Cash clears after rebootThe system forcibly clears memory at low RAMClose unnecessary applications manually or increase the amount of RAM (some Xiaomi models support virtual memory expansion)
Notifications don't come in the backgroundAuto Start or Background Activity DisabledCheck permissions in Settings β†’ Applications β†’ Application Management
The application is not retained in exceptionsRestricted firmware (e.g. MIUI Global for Europe)Update the software or use ADB (see Method 3)

Another important nuance: on HyperOS devices (such as Xiaomi 14 or Redmi K70), the optimization algorithm has changed. Now the system analyzes user behavior β€” if you rarely open an application, it can be excluded from the background even despite the settings.

Cleaning up the app cache

Closing of background processes

Optimizing the battery

Nothing. Everything's fine.-->

How to check if the exception works

To make sure that the application is truly protected from cleaning, follow the following steps:

  1. Cache Clearing Test: Open the app (like Google Maps) and download the maps. Close it and run the optimization manually (Security β†’ Clean). Open the app again - if the cards load quickly, the exception works.
  2. Background test: Send yourself a message in a messenger (like Viber), close the app and wait 10-15 minutes. If the notification comes, background activity is not blocked.

ADB

adb shell cmd appops query --user 0 Package applications

Look for lines RUN_ANY_IN_BACKGROUND and RUN_IN_BACKGROUND β€” They must have the status of allow.

If the tests fail, repeat setting exceptions or try alternative methods (e.g. ADB).Some firmware (e.g. MIUI China) may need to disable MIUI Optimization in the developer settings.

Alternative methods: if nothing helps

If the standard methods don’t work, try these solutions:

  • πŸ”§ Shutdown MIUI Optimization: Activate Developer Mode (7 taps according to version) MIUI). Go to Settings. β†’ Additionally. β†’ For developers, find a point. MIUI Optimization and turn it off. Reboot the phone.

⚠️ Note: Disabling this feature may cause some system applications to work unstable (e.g. Topics or Security).

Use of third-party utilities

Applications like Greenify or Brevent allow you to manually manage background processes, but they require root rights or ADB.

Transition to custom firmware

AOSP-based firmware (such as LineageOS or Pixel Experience) does not have aggressive MIUI optimization.

For devices on HyperOS (for example, Xiaomi 14) there is another way - the "No Limits" mode for the battery:

  1. Go to Settings β†’ Battery β†’ Battery Optimization.
  2. Select the application and set the No Limits mode.

πŸ’‘

On HyperOS devices, battery settings are prioritized, not clean-up exceptions. Always check both sections!

FAQ: Frequent questions about cleaning exceptions on Xiaomi

Can I add system applications (e.g. Google Play Services) to the exceptions?
No, most system applications (com.google.android.gms, com.miui.securitycenter, etc.) cannot be added to exceptions through standard settings. However, their optimization does not usually affect the operation of user programs. If you notice problems (for example, notifications do not work), try updating Google Play Services through the Play Market or clearing its cache.
After the MIUI update, all the exceptions were dropped. How do you restore them?
Unfortunately, MIUI does not save an exception list for major updates (e.g., from MIUI 13 to MIUI 14). You will have to add applications again. To avoid this in the future, you can: Create a backup through Settings β†’ Additional β†’ Backup and Reset (but exceptions may not be saved). Use ADB to automatically apply commands after the update (scripting skills are required).
How do you add an application to the exceptions that is not on the list?
If the application does not appear in the exclusion list, check if it is installed in main memory (not on the main memory). SD-Is it system (e.g. com.android.systemui) or hidden in settings (try to find it through Settings search) β†’ If the problem persists, use it. ADB (see method 3).
Will the battery run down faster if you turn off optimization for all applications?
Yes, aggressively disabling optimization for many applications can reduce battery life by 10-30% (depending on the model), and we recommend adding only mission-critical programs (e.g. messengers, navigators or fitness trackers) to the exceptions. For the rest, standard settings are sufficient MIUI.
Does this work on POCO and Black Shark?
Yes, POCO and Black Shark devices are MIUI-based (or HyperOS in newer models), so the instructions are fully applicable. Except that some Black Shark gaming smartphones have a separate Shark Space mode, where optimization is set up separately (in Settings β†’ Shark Space β†’ Optimization).