Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

android - How to auto restart a service when killed?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...