This code should run indefinitely. However, it successfully runs once and then never again. No exceptions are throw so I can't figure out what I did wrong. However, when nextExpression is not called, it does run indefinitely.
Here is the code:
onCreate() {
Runnable Runnable = new Runnable() {
public void run() {
System.out.println("Hello world");
nextExpression();
}
};
ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
executor.scheduleAtFixedRate(Runnable, 0, 3, TimeUnit.SECONDS);
}
int i = 0;
public void nextExpression() {
i++;
expression.setText("" + i);
}
I tested and it runs as it should, if you want to update a UI component you should do it with the main thread.
To update the textView from the Main thread you can do it like this: