• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Threading programme

Thread t = new Thread(new Runnable() {
public void run() {
Thread.sleep(1000);
//Do operations here
}
}
t.start();

Is this what you want?


In may or may not be important to your application, but be aware that this code suffers from drift. Thread.sleep(1000) will sleep for at least 1 second. It may actually be more by time the thread is actually scheduled for execution.

And you'll need to catch the InterruptedException thrown by Thread.sleep.


Another way that doesn't use threads is to use android.os.Handler's postAtTime or postDelayed methods.
 
Upvote 0
As Lemoncog said , use Timer and Timertask
here's an example

Code:
private Timer timer;
private long delay = 600;
public void start(){
timer.schedule(new Task(), delay);
}
class Task extends TimerTask {
        public void run() {
//your code goes here
timer.schedule(new Task(), delay);
        }
}

I used this for a cool down in my game tutorial, check it out
https://jimmaru.wordpress.com/2011/12/13/simple-andengine-game-v2-0-more-awesomeness/
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones