I'm triying to understand the differences between the three methods for managing the UI interactions.
I'm really confused with these three terms when triying to figure them out in a real case.
The below code shows the function of the invokeAndWait method, but if I replace it by invokeLater or getEventLock() the program will work exactly the same way.
Could someone please modify the code in order to show the differences between the three methods for updating the UI?
public final class HelloWorldMainScreen extends MainScreen
{
private LabelField labelField;
public HelloWorldMainScreen()
{
labelField = new LabelField("Hello World");
add(labelField);
MainScreenUpdaterThread thread = new MainScreenUpdaterThread(this);
thread.start();
}
public void appendLabelText(String text){
labelField.setText(labelField.getText()+"\n"+text);
}
}
public class MainScreenUpdaterThread extends Thread {
HelloWorldMainScreen mainScreen;
public MainScreenUpdaterThread(HelloWorldMainScreen mainScreen){
this.mainScreen = mainScreen;
}
public void run(){
for (int i = 0; i < 10; i++) {
try{
Thread.sleep(5000);
}catch(InterruptedException ex){};
UiApplication.getUiApplication().invokeAndWait(new Runnable() {
public void run() {
mainScreen.appendLabelText("Update");
}
});
}
}
}
These three concepts are very confusing for many starting people so any explanatory source code describing their functions will be strongly helpful for anybody, I think.
Thanks in advance!