-4

I need to run asynk task till two minutes in interval of every fiften seconds . Is there any way to do this ?

Dinesh Rijal
  • 137
  • 1
  • 2
  • 8

1 Answers1

2

try like this

void TimerTask(int count)
    {
        if(count>8) // 8 cyclses,because 60*2/15
            return;

        Timer myTimer = new Timer(); // Create timer
        myTimer.schedule(new TimerTask() {
            @Override
            public void run() {
                // run your async task there

                TimerTask(count++); //OnExecute

            }
        }, 0L, 15L * 1000);//every 15 sec (0L - seconds waiting for start)
    }

` Call it - TimerTask(0);

Alex
  • 66
  • 8