Android中的定时器和TimerTask [英] Timer and TimerTask in Android

查看:29
本文介绍了Android中的定时器和TimerTask的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序需要一个计时器.我已经编写了它,它在 PC 上的模拟器程序(Android 1.5/2.2)上运行良好.但它不适用于真机(Android 1.5).我做错了什么?

I need a timer for my program. I have written it and it works fine on PC in emulalator program (Android 1.5/2.2). But it doesn't work on the real device (Android 1.5). What am I doing wrong?

TimerTask task = new TimerTask() {
            public void run() {
                if (condition) {
                    myFunc();
                } else {
                    this.cancel();
                }
            }
        };
        Timer timer = new Timer();
        timer.schedule(task, 500, 85);

推荐答案

你需要cancel() timer 而不是timer task.

You need to cancel() timer not the timer task.

这篇关于Android中的定时器和TimerTask的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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