Diogo Dias
Diogo Dias

Reputation: 15

Wait funtion in a while cycle?

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
    }
}

Upvotes: 0

Views: 72

Answers (2)

PRATEEK BHARDWAJ
PRATEEK BHARDWAJ

Reputation: 2432

 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);

Upvotes: 1

Wajid
Wajid

Reputation: 2341

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.

Upvotes: 3

Related Questions