senzacionale
senzacionale

Reputation: 20916

timer.scheduleAtFixedRate is executed in a second not after delay time

i am using timer like:

Timer timer = new Timer();
timer.scheduleAtFixedRate(new CheckWifi(), 0, 50000); // 5 seconds

class Wifi extends BroadcastReceiver {

 protected class CheckWifi extends TimerTask {

        @Override
        public void run() {
        }
 }

but CheckWifi class is executed in a second not after 50 second like is set in scheduleAtFixedRate. Why?

Is it better to use Runnable instead of Timer?

Upvotes: 0

Views: 1156

Answers (1)

Dheeraj Vepakomma
Dheeraj Vepakomma

Reputation: 28717

You'll have to use:

timer.scheduleAtFixedRate(new CheckWifi(), 50000, 50000);

The second parameter specifies the delay before the first execution. The third parameter specifies the delay between subsequent executions.

Upvotes: 3

Related Questions