【发布时间】:2014-08-31 14:22:58
【问题描述】:
当需要将数据上传到服务器时,我想显示一个 ProgressDialog。
我已经检查了这个问题Best way to show a loading/progress indicator? 最好的答案是
ProgressDialog progress = new ProgressDialog(this);
progress.setTitle("Loading");
progress.setMessage("Wait while loading...");
progress.show();
// To dismiss the dialog
progress.dismiss();
当我试图在我的代码中实现它时,什么都没有显示!! 我在这里做错了什么?!
这是我的代码
private void UpdateData()
{
ProgressDialog progress = new ProgressDialog(this);
progress.setTitle("Loading");
progress.setMessage("Wait while loading...");
progress.show();
try
{
UpdateWSTask updateWSTask = new UpdateWSTask();
String Resp = updateWSTask.execute().get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
progress.dismiss();
}
【问题讨论】:
-
updateWSTask.execute().get()必须是updateWSTask.execute()。get()阻塞等待返回结果的 ui 线程。您希望任务是异步的。 -
如何从 updateWSTask.execute() 传递参数?
-
不要使用 get 只是用 execute 调用 asynctask
-
您可以使用接口作为活动的回调。 stackoverflow.com/questions/16752073/…
-
@Raghunandan 但他在 task.execute().get() 之前显示对话框,所以它不应该是可见的吗?
标签: android multithreading show progressdialog