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

落爺英雄遲暮 提交于 2020-01-04 05:59:51

问题


I have a Sticky Service and i'm stress testing the app by filling the phone's RAM. Once the RAM is full, the service is destroyed. Since it's a sticky service, it gets restarted automatically when the system has enough resources.

But this happens only on stock android devices like Moto/Nexus. Devices like Xiaomi or Lava do not restart the sticky service, even on 5.1

Is anyone aware of such problems with heavily customized ROMs? Any workarounds to schedule a restart of my service when the memory gets low?


回答1:


All stock android devices like works well because they use AOSP ROM's

These devices(HUAWEI,LAVA,XIAOMI) are shipped with pre-installed start managers or energy savers (most of the Huawei devices). If the app is not configured appropriately the services will be killed several seconds/minutes after the screen turns off - or it will not automatically be started after reboot.

Now with the feature called Protected Apps, I tried enabling in my app and still the sticky service is not getting started post the App Kill. also, furher observation is:-- The HUAWEI device does not even hold a foreground service

Now the possible workaround is:--

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.



来源:https://stackoverflow.com/questions/37768373/sticky-service-not-restarting-after-ram-full-on-xiaomi-huawei-lava

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!