Android 常规任务(相当于 cronjob) [英] Android regular task (cronjob equivalent)

查看:24
本文介绍了Android 常规任务(相当于 cronjob)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上次(由不同用户)提出这个问题时,答案是:

The last time this question was asked (by a different user), the answer response was:

如果这是在一个正在运行的活动中,您可以使用 Timer/TimerTask 和一个处理程序,或者您可以使用 postDelayed() 和一个 AsyncTask.

If this is in a running activity, you could use Timer/TimerTask and a Handler, or you could use postDelayed() and an AsyncTask.

此处:Android 重复任务

我仍在学习如何编写 android 程序.我已经掌握了我所知道的技能,包括线程,并且我的代码有很多问题.谁能举例说明如何使用:time/timertask and handler OR postDelayed() and AsyncTask.

I am still learning how to program android. I have gone through the skills I do know including threads and had many issues with my code. Can anyone give an example of how to use: time/timertask and handler OR postDelayed() and AsyncTask.

推荐答案

对于类似 Cron 的任务,你必须使用 AlarmManager,这是一个系统服务,要在你的代码中使用它,你需要调用:

For Cron like tasks you have to use AlarmManager, this is a system service, for using it in your code you need to call:

AlarmManager myAlarmManager = Context.getSystemService(Context.ALARM_SERVICE).

有关 AlarmManager 的完整文档此处.

Full docs about AlarmManager here.

这篇关于Android 常规任务(相当于 cronjob)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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