从processFinish在AsyncTask的Android的返回值 [英] Android return value from processFinish in AsyncTask
问题描述
在此跌破codeI想通过从 processFinish
的方法要使用的数据,在课外,但我无法修复的问题,我不能返回值 processFinish
在通话
的功能。
in this below code i want to pass data from processFinish
method to use that in outside class but i can not fix problem and i can not return value from processFinish
in call
function.
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<Void, Void, String> {
public AsyncResponse delegate=null;
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);
}
}
请帮我制定通话
方法输出
价值回归之外类。谢谢
please help me to develop call
method to return output
value to outside class. thanks
推荐答案
目前要实现AsyncResponce。 所以 替换
There you are implementing AsyncResponce. so Replace
new ProcessTask(rq, new AsyncResponse() {
@Override
public void processFinish(String output) {
MainResult = output;
}
}).execute();
到
new ProcessTask(rq, this).execute();
然后你的类 overrided
方法,P rocessFinish(字符串输出)
将调用。
Then your class overrided
method processFinish(String output)
will call.
和使用在processFinish(你的价值),而不是值由call()方法retured。
And use your value at processFinish() rather than value retured by call( ) method.
这篇关于从processFinish在AsyncTask的Android的返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!