Progress dialog not displayed in android?
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 p开发者_如何学编程rogress 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.
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.
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.
精彩评论