ProgressDialog并不只显示闪烁 [英] ProgressDialog doesn't show just flashes
问题描述
我有耗时功能上传/ *约10秒* /。开始上传前,我想显示ProgressDialog,当上传完成解雇ProgressDialog,我试图像
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);
}
});
问题是,进展并不说明10秒左右,只有闪烁,像是第一次上传,然后调用表演和解雇(我试图把上面显示线程,但它是一样的)。
该怎么办 ? (上载是无效的功能)
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)
推荐答案
您是上传code不应该在UI线程上运行。如果确实如此,那么它会阻止从其他做任何事情,如显示一个进度对话框线程。保存进度对话框,显示它,产生一个新的线程来完成上传,而上传完成后,使用处理,回到UI线程并关闭进度对话框
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
这篇关于ProgressDialog并不只显示闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!