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

Apps Threading programme

hi
i want to perform some task for every second of intervals.
but i am not getting the result for using the Thread.sleep(1000).

please suggest me how to write programme to full fill this task
 
Thread t = new Thread(new Runnable() {
public void run() {
Thread.sleep(1000);
//Do operations here
}
}
t.start();

Is this what you want?
 
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.
 
Back
Top Bottom