Get*_*awn 1 java generics android
下面这部分代码<String, Void, Bitmap>是什么意思?我甚至都不知道甚至调用了这种语法.
private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
}
Run Code Online (Sandbox Code Playgroud)
这是原始代码(从这里找到:http://developer.android.com/guide/components/processes-and-threads.html):
public void onClick(View v) {
new DownloadImageTask().execute("http://example.com/image.png");
}
private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
/** The system calls this to perform work in a worker thread and
* delivers it the parameters given to AsyncTask.execute() */
protected Bitmap doInBackground(String... urls) {
return loadImageFromNetwork(urls[0]);
}
/** The system calls this to perform work in the UI thread and delivers
* the result from doInBackground() */
protected void onPostExecute(Bitmap result) {
mImageView.setImageBitmap(result);
}
}
Run Code Online (Sandbox Code Playgroud)
AsyncTask<String, Void, Bitmap>
Run Code Online (Sandbox Code Playgroud)
告诉AsyncTask由3种不同的类型描述,String作为第一个参数,Void作为第二个参数,Bitmap作为第三个参数,当您使用AsyncTask时.
这在Java中称为Generics,从Java5开始引入.请阅读本教程以了解有关泛型的更多信息.这是关于android AsyncTasktask如何使用泛型的javadoc.
更新:来自AsyncTask javadoc
1) Params, the type of the parameters sent to the task upon execution.
2) Progress, the type of the progress units published during the background computation.
3) Result, the type of the result of the background computation.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
364 次 |
| 最近记录: |