Android service not restarted

谁说胖子不能爱 提交于 2019-12-11 04:52:56

问题


I have a service that tracks the user locations. It doesn't have to run 24x7 but it should run for the duration of the trip. Following are the things that I have implemented till now to ensure it's continuous functioning :

  • started service as foreground
  • used "START_STICKY"
  • started an alarm which checks every 10 mins if service is running. If not it starts service.

Despite of all these measures, for some devices(like MI 3w) service gets killed within 10 mins and doesn't restart at all(not even after waiting for 12 hours!). From extensive googling I have learned that when process is killed by OS the alarm doesn't trigger(correct me if I am wrong), so this might be the case here. But what happened to "START_STICKY"?

So my queries are :

  • What happened to START_STICKY? Is it an OS bug (OS V6)?
  • Why does OS cancel all the set alarm while killing the process?
  • Most importantly how to ensure that my service runs for the trip duration?

回答1:


Some devices(like Mi 3w)

What happened to START_STICKY? Is it an OS bug (OS V6)?

Nothing. Xiaomi does not allow the App to auto start. No bug, it's a Memory management technique of Xiaomi.

Conclusion

It doesn't new on Xiaomi because Xiaomi has a feature called app permission, where a user has to allow the app to start automatically (Service).

Go like this and allow your app to autostart:

Settings > permissions > Autostart



来源:https://stackoverflow.com/questions/41973651/android-service-not-restarted

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