Then come Huawei and Xiaomi with their Android modifications to "improve battery life."
Yes Xiaomi, Huawei and some other manufacturers have their own “Battery Saver” or “Security” layer, which kills or restricts background running applications in order to improve security / battery backups, unless the user selects your application in the appropriate device settings.
What I learned about Xiaomi is that they are familiar with famous apps like Facebook, Whatsapp, etc. But you cannot request Xiaomi to whitelist your application.
This can damage the background launch of applications so badly that after a week or two the application needs to be reinstalled. Even cleansing data will not thaw the application.
These vendor applications simply terminate your application process. Therefore, your application should behave in such a way that termination at any time should not create an inconsistent state.
In addition, you can always display a pop-up window for the user after installation, asking him to go and whitelist your application in battery saving mode. In Xiaomi, the user needs to select "Do not limit background activity", and also enable "Autostart" for your application. As far as I know, there is no other solution.
Let me know if you find one;)

source share