开发者

Timer and TimerTask in Android

开发者 https://www.devze.com 2023-03-15 03:54 出处:网络
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 (And开发者_如何学编程roid 1.5). What am I doin

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 (And开发者_如何学编程roid 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);


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

0

精彩评论

暂无评论...
验证码 换一张
取 消