每隔几个小时运行一次任务 [英] Running a task every few hours

查看:30
本文介绍了每隔几个小时运行一次任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个方法,即使用户没有重新打开应用程序,我也需要每隔几个小时运行一次.最好的方法是什么?我应该使用 Timer 类还是警报管理器?谢谢!

I have a method that I need to run every few hours even if the user didn't reopen the app. What is the best way to go? Should I use the Timer class or Alarm manager? Thanks!

推荐答案

您应该使用 AlarmManager 为此安排服务.请参阅此 Vogella 教程.

You should use AlarmManager to schedule services for this. See this Vogella tutorial.

这篇关于每隔几个小时运行一次任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆