I am making a post to a web service from my android activity through AsyncTask inner class. My idea is that each time I post to the web service. I want the AsynTask to return a string value to the Activity, informing the activity if there was a successful post or a failure in posting to the webservice. I did this through a get method but I noticed when I click the button to post my UI would freeze for a while before responding. but the post still works. Please is there a way I can prevent this UI freezing. My code is below.
This is my doBackground method in my AsyncTask class
@Override
protected String doInBackground(String... arg0) {
// TODO Auto-generated method stub
String result = "";
PatientModel patient = new PatientModel();
patient.setPhone(Phone);
patient.setEmail(Email);
patient.setGCMRegistrationID(GCMRegistrationID);
JSONHttpClient jsonHttpClient = new JSONHttpClient();
patient = (PatientModel) jsonHttpClient.PostObject(RestfulServiceUrl.RegisterPatient, patient, PatientModel.class);
GCMRegistrar.setRegisteredOnServer(context, true);
if(patient != null) {
result = patient.getPhone();
}
else if(patient == null){
result = "failed";
}
return result;
}
This is the script were I collect the values in my activity
try {
String result = new RegisterPatient(RegisterActivity.this,resource,email,phone,regId).execute().get();
}
catch(Exception e){
}