When developing a VPN service, I encountered a problem on a Huawei device (Huawei P smart 2019 / EMUI 12.0.0 / Android 10) – I suspect I will encounter a similar problem on other devices of the brand. After starting the VPN service and minimizing applications to the background, the system kills my service.
I tried various solutions (including from the dontkillmyapp site), such as:
- automatic restart of the service with the
START_STICKY
flag (the system can kill it 3 times in 15 seconds, then restart it after 5-15 minutes and immediately kill it again); - wakelock (just no effect);
- monitored resource consumption (an application with a service in the background consumes up to 200 MB with 750-800/3000 MB free). That is, there are enough resources and the application does not consume a lot;
For the experiment, I even made an “empty” application with 1 button and a VPN service with minimal parameters. The total code size did not exceed 100 lines. But the behavior towards the background service is exactly the same – the system constantly kills it.
Only one solution seemed effective to me at the moment: removing ADB from the device. In this case, the background service is not killed by the system. But this is completely unusable for potential users, since the removal process is difficult for the average user.
What ways are there to support the background service on Huawei devices other than those listed?