I have an activity which checks username availability via .net web services, I need to show a ‘please wait’ message during the call as it can take a second or two – I have experimented with AsyncTask and Threading but the problem I have is I actually want to block the main (and only) thread until the web service call has completed as I am depending on the result from it to process other logic.
I have tried allsorts but no joy – can anyone help please?
As requested, here is a section of my code :
private OnClickListener RegistrationListener = new OnClickListener() {
public void onClick(View v) {
ClearFieldHighlighting();
if (ValidateData()) {
if (IsOnline()) {
if (UsernameIsAvailable()) {
try {
iNETUserID = CreateOnlineUser();
} catch (Exception e) {
}
..more code..
}
Here is the ‘UsernameIsAvailable’ function :
public boolean UsernameIsAvailable() {
Boolean bUsernameIsAvailable = false;
SoapObject request = new SoapObject(TA.sNAMESPACE,
TA.METHOD_IsUsernameAvailable);
request.addProperty("sUsername", sEmail);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(
TA.WEBSERVICES_URL);
try {
androidHttpTransport.call(TA.SOAP_ACTION_IsUsernameAvailable,
envelope);
SoapObject thisresponse = (SoapObject) envelope.bodyIn;
for (int i = 0; i < thisresponse.getPropertyCount(); i++) {
Object obj = thisresponse.getProperty(i);
SoapPrimitive soapPrimitive = (SoapPrimitive) obj;
bUsernameIsAvailable = Boolean.parseBoolean(soapPrimitive
.toString());
}
} catch (Exception e) {
}
return bUsernameIsAvailable;
}
I am using KSoap2 which is an external jar file to handle the web service stuff
Thanks
Mike
You can structure your code in the following way: