0

Is there any way to do a wait() function, in my case, in Android Studio?

function example ()
{
    while () 
    {
        //do something 
        //wait (x seconds) then go back
    }
}
Diogo Dias
  • 15
  • 8

2 Answers2

3

You may achieve this way:

//in your method, use the Timer Schedule function:
new Timer().schedule(  
    new TimerTask() {
        @Override
        public void run() {
            //TODO: do something here of your interest.
        }
    },
    2000
);

Here I have kept the delay for 2 seconds (2000 milliseconds). You may change that according to your need.

Wajid
  • 2,235
  • 1
  • 19
  • 29
1
 int interval = 3000;//milliseconds interval for delay
        new Handler().postDelayed(new Runnable() {


            @Override
            public void run() {


            }

            private void finish() {
                // TODO Auto-generated method stub

            }
        }, interval);
PRATEEK BHARDWAJ
  • 2,364
  • 2
  • 21
  • 35