I am trying to display a progress dialog during the onCreate() method of one of my activities, have the work done to populate the screen done in a thread, and then dismiss the progress dialog.
Here is my onCreateMethod()
dialog = new ProgressDialog(HeadlineBoard.this);
dialog.setMessage("Populating Headlines.....");
dialog.show();
populateTable();
The populateTable method contains my thread and the code to dismiss the dialog, but for some reason. The activity comes up blank for about 10 secs(doing the populateTable() work), and then I see the screen. I never see the dialog displayed, any ideas?
Here is the populateTable() code:
//Adds a row to the table for each headline passed in
private void populateTable() {
new Thread() {
@Override
public void run() {
//If there are stories, add them to the table
for (Parcelable currentHeadline : allHeadlines) {
addHeadlineToTable(currentHeadline);
}
try {
// code runs in a thread
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.dismiss();
}
});
} catch (final Exception ex) {
Log.i("---","Exception in thread");
}
}
}.start();
}
If there are stories, add them to the table
. You run this code on UI thread, not on the thread you've created. – Volodymyr Lykhonisdialog.dismiss();
– Volodymyr Lykhonis