我已经在几个项目中使用这个 AsyncTask,但仍然不太明白 <String, Void, String>
的作用意思是。这些是否意味着未实现方法的参数类型?有什么命令吗(String、Void、String分别对应什么方法)?
最佳答案
android.os.AsyncTask<Params, Progress, Result>
异步任务使用的三种类型如下:
Params, the type of the parameters sent to the task upon execution.
Progress, the type of the progress units published during the background computation.
Result, the type of the result of the background computation.
现在我用简单的话来理解:
参数:(在您的情况下为字符串)是 AsyncTask
的参数需要。调用execute
时必须传递这个方法
进度:(在您的例子中为 Void)是进度的类型。 Void 表示您没有使用它。如果是整数,您可以使用 10、20、30 等值...并使用这些值在屏幕上显示进度条。
结果:(在您的情况下为字符串)是 AsyncTask
的内容作为结果返回。您正在返回一个字符串。您可以返回任何您想要的对象。
简单来说,有点像一个方法,Params是参数,Result是返回类型,progress告诉你处理进度的状态。
要进一步了解,请参阅 this tutorial , 也引用同一页可能会有帮助:
AsyncTask<TypeOfVarArgParams, ProgressValue, ResultValue>
TypeOfVarArgParams is passed into the doInBackground() method as input, ProgressValue is used for progress information and ResultValue must be returned from doInBackground() method and is passed to onPostExecute() as parameter.
关于android - AsyncTask<String, Void, String> 通用类型。安卓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13565208/