如何像回调函数一样使用AsyncTask
我遇到的情况如下所示,我找不到任何解决方案。
我将从一个 webmethod 中获取结果值并将其设置为一个参数,然后在对其进行一些操作后,我将其发送到另一个 webmethod,它将由另一个方法使用,等等。这是我想要做的:
x = webMethodA();
y = webMethodB(x+3);
if(y){
z=10;
} else {
z=1000;
t = webMethodC(z);
我正在使用调用 webmethods 时使用 AsyncTask,因为 honeycomb 不支持在 UI 线程上调用 webservices。我通过 onPostExecute 获取结果值,但无法发送回调用方方法。
我该如何克服这个问题?
setMethodName("GetTarih");
KeyValuePair[] parameters = new KeyValuePair[2];
parameters[0] = new KeyValuePair("Rep", "TEST001");
parameters[1] = new KeyValuePair("Tarih", String.valueOf(Util.getOADateByToday()));
CallSoap soap = new CallSoap(uri, soapAction, parameters);
soap.setDataDownloadListener(new CallSoap.DataDownloadListener() {
public void dataDownloadedSuccessfully(String data) {
Log.e("aaaa",data);
tarih = data;
}
public void dataDownloadFailed() {
// TODO Auto-generated method stub
}
});
soap.execute("");
//I want to continue from this line with parameter named tarih.
I am in a case which can be seen below that I could not find any solution.
I am going to take result value from a webmethod and set it to a parameter then after some operation with it I will send it to another webmethod and it will used by another method, etc. Here is what I want to do:
x = webMethodA();
y = webMethodB(x+3);
if(y){
z=10;
} else {
z=1000;
t = webMethodC(z);
I am using AsyncTask while calling webmethods because honeycomb does not support to call webservices on UI thread. I am geting the result value by onPostExecute but can not send to caller method back.
How do I overcome this problem?
setMethodName("GetTarih");
KeyValuePair[] parameters = new KeyValuePair[2];
parameters[0] = new KeyValuePair("Rep", "TEST001");
parameters[1] = new KeyValuePair("Tarih", String.valueOf(Util.getOADateByToday()));
CallSoap soap = new CallSoap(uri, soapAction, parameters);
soap.setDataDownloadListener(new CallSoap.DataDownloadListener() {
public void dataDownloadedSuccessfully(String data) {
Log.e("aaaa",data);
tarih = data;
}
public void dataDownloadFailed() {
// TODO Auto-generated method stub
}
});
soap.execute("");
//I want to continue from this line with parameter named tarih.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想在线程之间发送消息/数据/捆绑包,请查看 Message 和 Handler 类。
您的“工作”线程将创建一条消息来包含将发送到您的 UI 线程的结果。
当您创建 Handler 时,请确保在 UI 线程中创建它。
If you're wanting to send messages/data/Bundles between threads take a look at Message and Handler classes.
Your 'worker' thread will create a message to contain the result which will be sent to your UI thread.
When you create your Handler be sure you create it in the UI thread.