Reputation: 15
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
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
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