Android 中不显示进度对话框?
我在点击 Web 服务时使用进度对话框并等待 Web 服务的响应,一旦收到响应,我就会关闭进度对话框。这是我用于此目的的代码,
dialog= ProgressDialog.show(Settings.this, "","Synchronisation with server...", false);
request = new SoapObject(NAMESPACE, METHOD_NAME);
envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
androidHttpTransport = new AndroidHttpTransport(URL);
request.addProperty("mtest","1");
envelope.setOutputSoapObject(request);
try
{
System.gc();
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
}
}
dialog.dismiss();
}
catch (Exception aE)
{
aE.printStackTrace ();;
}
但没有显示进度,如果我发送请求时连接了 Web 服务,应用程序似乎处于空闲状态并且在收到响应之前不显示任何进度,我需要显示一些进度。
如果Web服务未连接,则会显示进度,但我们无法手动关闭它。 我需要在访问网络服务时显示进度指示,无论是作为单独的进度还是作为标题本身的一部分。如果有人知道请帮帮我。
谢谢。
I use the progress dialog while hitting web service and wait for response from web service ,once i got the response i dismiss the progress dialog. here is the code i use for that,
dialog= ProgressDialog.show(Settings.this, "","Synchronisation with server...", false);
request = new SoapObject(NAMESPACE, METHOD_NAME);
envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
androidHttpTransport = new AndroidHttpTransport(URL);
request.addProperty("mtest","1");
envelope.setOutputSoapObject(request);
try
{
System.gc();
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
}
}
dialog.dismiss();
}
catch (Exception aE)
{
aE.printStackTrace ();;
}
but the progress is not appear, if web service connected if i send the request , the application seems to be idle and does not show any progress until it got the response , i need to show some progress.
If web service is not connected the progress is displayed , but we can`t dismiss it manually.
i need to show indication of progress while hitting web service, either as separate progress or as a part of title itself. If any one know please help me out.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用 Handler 将远程调用包装到辅助线程或使用 AsyncTask 做这项工作。
原因是,当您执行 ProgressDialog.Show 时,它安排了下一次更新(在 UI 线程中)的显示,该线程与您连接 Web 服务的线程相同;因此,它永远没有机会这样做,因为您的 Web 服务正在占用 UI 线程。
Try to wrap your remote calls to a secondary thread with Handler or use a AsyncTask to do the work.
Reason is, when you do ProgressDialog.Show, it scheduled the show in next update (in UI thread), which is the same thread as you are connecting web service; Hence, it never get the chance to do so since your web service is holding the UI Thread.
很多人都面临这个问题,甚至我也面临同样的问题。最好的解决方案是使用异步任务。 Hear 是该文件的示例代码。它可能对你有帮助。
Many people face the this problem, even i also facing same problem. The best solution for this is to use the Async Task. Hear is a sample code for that . It may help you.