18

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);
Aditya
  • 5,509
  • 4
  • 31
  • 51
Scit
  • 1,722
  • 4
  • 15
  • 18
  • possible duplicate of [Android - Controlling a task with Timer and TimerTask?](http://stackoverflow.com/questions/2161750/android-controlling-a-task-with-timer-and-timertask) – Felix Kling Jun 08 '12 at 12:36
  • Go through this [android-controlling-a-task-with-timer-and-timertask](http://stackoverflow.com/questions/2161750/android-controlling-a-task-with-timer-and-timertask) – Rasel Jun 25 '11 at 12:15

1 Answers1

18

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

Jarek Potiuk
  • 19,317
  • 2
  • 60
  • 61