Android Kills Background Services in Xiaomi, Huawei etc

馋奶兔 提交于 2019-12-02 06:46:43

There are some customizations on Chinese roms regarding app lifecycle.

Xiaomi kills foreground services indiscriminately (xiaomi redmi note4 (Android N), note 7 (Android P)). So it's really difficult to have the same behavihour on all phones.

You can try to relaunch your foreground service using an alarm with a broadcast receiver. When you app is being killed you need to set this alarm. When the intent is received try to start the foreground service with startForeground(). Remember also to bind the foreground service and disable battery limitation (and others things related) according to your device.

I don't know if this works because we have no necessity to implement such a method. But you could give it a try.

Remember that for Android >= Oreo the only way for a service to survive and works seems to be the foreground service way.(Bound service with battery optimization off for some devices)

You can find useful material at:

Never Ending background service

LocationUpdatesForegroundService

The second example works on emulator on different version of android(5/7). It works on Galaxy S3 with Resurrection Remix rom (Android 7) and works on some Huawei models (Oreo, Pie).

Work with services in android is really difficult. Have patience and go on.

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