Android服务未重新启动 [英] Android service not restarted
问题描述
我有一个跟踪用户位置的服务。它不必全天候(24x7)运行,但可以在旅途中运行。以下是我迄今为止为确保其连续运行而执行的操作:
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 :
- 将服务作为前台启动
- 使用了 START_STICKY
- 启动了一个警报,该警报每10分钟检查一次服务是否正在运行。如果没有,它将开始服务。
尽管采取了所有这些措施,但对于某些设备(如MI 3w),服务会在10分钟内被杀死,并且根本不会重启(即使等待了12个小时也不会重启!)。通过广泛的谷歌搜索,我知道当操作系统终止进程时,警报不会触发(如果我错了,请纠正我),所以这里可能是这种情况。但是 START_STICKY怎么了?
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"?
所以我的查询是:
- START_STICKY怎么了?是操作系统错误(OS V6)吗?
- 为什么操作系统在取消进程的同时取消所有设置的警报?
- 最重要的是如何确保
推荐答案
某些设备(例如Mi 3w)
START_STICKY怎么了?是操作系统错误(OS V6)吗?
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:
设置>权限>自动启动
这篇关于Android服务未重新启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!