Okay.. I am doing something similar to the below:
private void onCrea开发者_运维百科te() {
final ProgressDialog dialog = ProgressDialog.show(this, "Please wait..", "Doing stuff..", true);
Thread t = new Thread() {
public void run() {
//do some serious stuff...
dialog.dismiss();
}
};
t.start();
t.join();
stepTwo();
}
However, what I am finding is that my progress dialog never even shows up. My App stalls for a moment so I know it is chugging along inside of thread t, but why doesnt my dialog appear?
IF I remove the line:
t.join();
Then what I find happens is that the progress dialog does show up, but my app starts stepTwo(); before what happens in the thread is complete..
Any ideas?
Try to use an handler
public class MyActivity {
private Handler handler;
private void onCreate() {
handler = new Handler() {
@Override
public void handleMessage(Message msg) {
pd.dismiss();
stepTwo();
}
};
final ProgressDialog dialog = ProgressDialog.show(this, "Please wait..", "Doing stuff..", true);
Thread t = new MyThread() {
t.start():
}
private class MyThread extends Thread() {
public void run() {
//do some serious stuff...
handler.sendEmptyMessage(0);
}
}
}
Your join() line blocks the UI thread that runs the ProgressDialog. You are therefore blocking layouts, drawings, etc.
精彩评论