在小米/华为/熔岩上 RAM 满后粘性服务不会重新启动

Sticky Service not restarting after RAM full on Xiaomi / Huawei / Lava

我有一个 粘性服务,我正在通过填充 phone 的 RAM 来对应用程序进行压力测试。一旦 RAM 已满,服务就会被销毁。由于它是一个粘性服务,当系统有足够的资源时它会自动重启。

但这只发生在像 Moto/Nexus 这样的库存 android 设备上。小米或 Lava 等设备不会重新启动粘性服务,即使在 5.1

有人知道高度定制的 ROM 存在此类问题吗?在内存不足时安排重新启动我的服务的任何解决方法?

所有库存 android 设备都运行良好,因为它们使用 AOSP ROM

这些设备(HUAWEI、LAVA、XIAOMI)预装了启动管理器或节能器(大多数华为设备)。如果应用程序配置不当,服务将在屏幕关闭后终止数次 seconds/minutes - 或者重启后不会自动启动。

现在有了名为受保护应用程序的功能,我尝试在我的应用程序中启用,但粘性服务仍然没有启动 post 应用程序终止。 另外,进一步观察是:--华为设备甚至没有前台服务

现在可能的解决方法是:--

We can use Alarm Manager class to make sure that the service is running when it's necessary. So this Alarm manager can be used to create a timer which checks from time to time if the service should be running and restart it. This time interval needs to be set considering the possible impact on battery consumption.