Timer和TimerTask实现计时
作者:
撕裂的我 | 来源:发表于
2017-10-16 17:30 被阅读0次Timer timer = new Timer();
mTime = 15;
time_tv.setText(String.valueOf(mTime));
mTimerTask = new TimerTask() {
@Override public void run() {
runOnUiThread(new Runnable() {
@Override public void run() {
mTime--;
time_tv.setText(String.valueOf(mTime));
if (mTime == 0) {
manager.stopDetector();
cancelTask();
toFailedActivity("检测超时");
}
}
});
}
};
timer.schedule(mTimerTask, 1000, 1000);
private void cancelTask() {
if (mTimerTask != null && timer != null) {
if (!mTimerTask.cancel()) {
timer.cancel();
mTimerTask.cancel();
}
}
}
本文标题:Timer和TimerTask实现计时
本文链接:https://www.haomeiwen.com/subject/zrhluxtx.html
网友评论