Some device manufacturers use a non-standard method to save battery by essentially killing any App that should be set to work in the background so this removes the permissions that we need.
Xiaomi is notorious for their aggressive battery optimization so we have to exempt Boomerang Parental Control (for kids) or Manage SPIN (for adults) from this aggressive battery optimization. Thankfully, Xiaomi does provide a method to have the permissions "stick."
- Settings > Advanced Settings > Battery manager > Power plan is set to Performance
- Device Settings > Advanced Settings > Battery Manager > Protected apps – your app needs to be Protected
- Device Settings > Apps > your app > Battery > Power-intensive prompt and Keep running after screen off
- Settings > Additional Settings > Battery & Performance > Manage apps’ battery usage and here:
- Switch Power Saving Modes to Off
- Choose the next options: Saving Power in The Background > Choose apps > select your app > Background Settings > No restrictions
App battery saver
Security > Battery > App Battery Saver > your app > No restriction
As per this article by Xiaomi: Open Security app > Permissions > Auto-start Enable Autostart for desired apps.
When you open recent apps tray, drag your app downwards – it will be locked. So even if you clear recent apps it will not clear from the background. Drag downwards again to clear your app from the background.
Tips from https://dontkillmyapp.com/xiaomi