Android 中不显示进度对话框?

发布于 2024-11-07 03:04:20 字数 1016 浏览 4 评论 0原文

我在点击 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

若有似无的小暗淡 2024-11-14 03:04:20

尝试使用 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.

樱桃奶球 2024-11-14 03:04:20

很多人都面临这个问题,甚至我也面临同样的问题。最好的解决方案是使用异步任务。 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文