Android : Android get result of processFinish as an Interface method with AsyncTask

on Wednesday, September 10, 2014


in this below simple code i must be return value from call method before get value from AsyncResponse interface class. my code is not correct and return NULL and i can not get result from processFinish to return that with call


Interface:



public interface AsyncResponse {
void processFinish(String output);

}


public class WSDLHelper implements AsyncResponse{ public SoapObject request;



private String MainResult;

public String call(SoapObject rq){

new ProcessTask(rq, this).execute();
return MainResult;

}

@Override
public void processFinish(String output) {
MainResult = output;
}


}


class ProcessTask extends AsyncTask { public AsyncResponse delegate;



SoapObject req1;

public ProcessTask(SoapObject rq, AsyncResponse delegate) {
req1 = rq;
this.delegate = delegate;
}

@Override
protected void onPreExecute() {
super.onPreExecute();
}

@Override
protected String doInBackground(Void... params) {

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(this.req1);

AndroidHttpTransport transport = new AndroidHttpTransport(Strings.URL_TSMS);
transport.debug = true;

String result = null;
try {
transport.call(Strings.URL_TSMS + this.req1.getName(), envelope);
result = envelope.getResponse().toString();
} catch (IOException ex) {
Log.e("" , ex.getMessage());
} catch (XmlPullParserException ex) {
Log.e("" , ex.getMessage());
}

if (result.equals(String.valueOf(Integers.CODE_USER_PASS_FALSE))) {
try {
throw new TException(PublicErrorList.USERNAME_PASSWORD_ERROR);
} catch (TException e) {
e.printStackTrace();
}
}

return result;
}

protected void onPostExecute(String result) {
delegate.processFinish(result);
}


}


0 comments:

Post a Comment