我在哪里可以延长AsyncTask的? [英] Where do I extend the AsyncTask?
问题描述
我有包含以下元素的登录系统:
I have a login system consisting of the following elements:
LoginActivity使用的LoginController使用RESTClient实现调用与执行)的Web服务(。我想被异步执行调用Web服务,但我还需要一个对话框,同时呼叫正在作出通知的相关信息的用户。执行不返回任何东西。
LoginActivity uses LoginController uses RestClient to call a web service with Execute(). I want the call to the web service to be performed asynchronously but I also need a dialog box to notify the user of relevant information while the call is being made. Execute does not return anything.
我将如何去这样做呢?我在哪里可以使用AsyncTask的?
How will I go about doing this ? Where do I use AsyncTask ?
推荐答案
AsyncTask的有几个方法,可以帮助你与此有关。
AsyncTask has a few methods that will help you with this.
延长AsyncTask的:
Extend the AsyncTask:
public class MyTask extends AsyncTask<Object, Void, Void>
@Override
protected void onPreExecute() {
// show progress dialog
}
@Overrride
protected Void doInBackground(Object... params) {
HttpUriRequest req = (HttpUriRequest) params[0];
String myString = (String) params[1];
// connect
return null;
}
@Override
protected void onPostExecute(Void result) {
// hide dialog
}
}
要带参数执行此,试试这个:
To execute this with parameters, try this:
myTask.execute(request, "aString");
在哪里请求类型HttpUriRequest的对象。记住的事情参数的顺序。
Where request is an object of type HttpUriRequest. Remember the order of the parameters matter.
如果你想在服务处于连接您可以使用此方法RASEL说要更新状态:
If you want to update the status while the service is connecting you can use this method as Rasel said:
onProgressUpdate() {
// Update view in progress dialog
}
这篇关于我在哪里可以延长AsyncTask的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!