你如何使用的TimerTask来运行一个线程? [英] How do you use a TimerTask to run a thread?

查看:140
本文介绍了你如何使用的TimerTask来运行一个线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我挣扎找到在Android上的TimerTask函数文档。 我需要运行一个线程使用TimerTask的间隔,但不知道如何去这一点。 任何意见或例子会大大AP preciated。

I'm struggling to find documentation for the TimerTask function on Android. I need to run a thread at intervals using a TimerTask but have no idea how to go about this. Any advice or examples would be greatly appreciated.

推荐答案

您使用的 定时器 ,并为您当您计划的TimerTask 使用任何自动创建一个新主题在计划 - 方法。

You use a Timer, and that automatically creates a new Thread for you when you schedule a TimerTask using any of the schedule-methods.

例如:

Timer t = new Timer();
t.schedule(myTimerTask, 1000L);

这将创建属于该计时器线程运行 myTimerTask 定时器每秒一次。

This creates a Timer running myTimerTask in a Thread belonging to that Timer once every second.

这篇关于你如何使用的TimerTask来运行一个线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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