This example is copied from a book on Android. As you can see from my question, I am new to Android and trying to understand. This application should crash but it does not (I am updating UI from another thread. Which is not allowed.It should cause a crash. It does not. Why?). My code is:
final ProgressDialog dialogue = ProgressDialog.show(this, "title", "message");
new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
try {
Thread.sleep(7000);
dialogue.dismiss();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}).start();
This is done in OnCreate function. I am confused with line – dialogue.dismiss(); Isn’t that updating UI (dismissing dialogue) from another thread? Why does this app not cause segmentation fault?
Thanks.
the dismiss() method can be run safetly on any thread as described in the Android documentation.