I have time consuming function upload /* around 10 sec */. I am trying before start upload to show ProgressDialog and when upload finishes to dismiss ProgressDialog and I trying like
pd = ProgressDialog.show(Uploader.this,
"Connecting...", "Uploading",
true, false);
Uploader.this
.runOnUiThread(new Runnable() {
public void run() {
upload();
handler.sendEmptyMessage(0);
}
});
Problem is that Progress doesn’t show for around 10s, only flashes, like it first upload and then call show and dismiss ( I tried to put show above thread, but it is the same ).
What to do ? ( Upload is void function)
You’re upload code should not run on the UI thread. If it does, then it will block that thread from doing anything else, such as displaying a progress dialog. Save your progress dialog, show it, spawn a new thread to do the upload, and when the upload is complete, use a Handler to get back to the UI thread and close the progress dialog