How to auto restart a service when killed?

最后都变了- 提交于 2019-11-28 06:12:49

问题


I have already red many posts about the subject, some of these works, but only on some devices. For example it works on my Nexus 4, Nexus 5 with cyaogenmod, but not on my Xiaomi Mi2s (jelly beam 4.1.1)

I tried setting it sticky, using alarm, and broadcast receiver on destroy. But neither of them worked out. When I kill the application it never wake up again. But on the same device Whatsapp works perfectly, and even if I kill it, it wake up again..

Is there any way to do it without use GCM?

Some of the link I already looked up:

How to restart a killed service automatically?

Service that repeatedly runs a method, after an amount of time

https://stackoverflow.com/a/21551045/627307


回答1:


I'm not sure if it will solve the issue for you or not but it worked for me.

I'm running MIUI 6.6.10

  1. Open the Security app provided by Xiaomi

  2. Click on permissions -> Autostart

  3. Here allow your app to auto start

WhatsApp and all famous apps work because Xiaomi white listed them and allowed them to autostart.



来源:https://stackoverflow.com/questions/26615633/how-to-auto-restart-a-service-when-killed

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