有一个持续运行计时器并每五秒执行一次任务的服务会更好吗?或者让警报管理器每五秒启动一次服务会更有效率吗?每秒怎么样?我很想听听您的回答。谢谢!
最佳答案
根据 the AlarmManager documentation ,它仅适用于您想在特定时间运行的情况。对于您所说的内容,您需要使用带有 postDelayed() 的处理程序。
Note: The Alarm Manager is intended for cases where you want to have your application code run at a specific time, even if your application is not currently running. For normal timing operations (ticks, timeouts, etc) it is easier and much more efficient to use Handler.
关于android - Android中哪种类型的服务会占用更多的系统资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6391088/