Android上运行一个任务周期 [英] Android run a Task Periodically

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

问题描述

我想在x秒后更新某一个领域的机器人活动定期运行的方法。我知道它可以在TimerTask的做,但什么是做到这一点的最好方法是什么? code样品将是有益的。

I want to run a method periodically in an android activity which updates a certain field after x seconds. I know it can be done in timerTask but what is the best way to do it? Code samples would be helpful.

推荐答案

您应该使用处理程序 postDelayed 功能。你可以在这里找到例如:<一href="http://stackoverflow.com/questions/6242268/repeat-a-task-with-a-time-delay/6242292#6242292">repeat具有时间延迟的任务

You should use Handler and its postDelayed function. You can find example here: repeat a task with a time delay

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

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