new Thread(new Runnable() { @Override public void run() { // Long running operation in the background ... // Update a TextView on the UI thread runOnUiThread(new Runnable() { @Override public void run() { myTextView.setText("Updated from background thread"); } }); } }).start();
runOnUiThread(new Runnable() { @Override public void run() { progressDialog.dismiss(); } });In both examples, the runOnUiThread() method is called with a new Runnable object that contains the code to be executed on the UI thread. The runOnUiThread method is part of the android.app.Activity package library, which is used to build user interfaces for Android applications.