Reputation: 11
I have written a java program where I need a continuous loop in the background. But with a normal while loop does not work the program.
In my program a method should be executed either all the time or every second. In this method, many conditions should be checked and a label should be updated, which indicates a time . I have already programmed this method, but I do not know how to write a loop that runs in the background so continue buttons can be pressed.
Upvotes: 0
Views: 4483
Reputation: 734
Use a Thread:
Thread thread = new Thread(new Runnable() {
public void run() {
doSomething();
}
});
thread.start;
Everything in the run method will be executed in another thread, so it's not blocking the ui.
Upvotes: 1