因为你使用了2个不同类型的参数,所以你可以使用构造函数(或者你要传递的参数使用getter、setter):
public class Helper extends AsyncTask<Integer, Void, Void> {
//The filed you want to pass
private SmbFile file;
private String desPath;
private SmbFile folder;
private String tempStore;
private File file;
private SmbFile destination;
//Create setter
public void setFile(SmbFile file) {
this.file = file;
}
public void setDesPath(String desPath) {
this.desPath = desPath;
}
public void setFolder(SmbFile folder) {
this.folder = folder;
}
public void setTempStore(String tempStore) {
this.tempStore = tempStore;
}
public void setFile(File file) {
this.file = file;
}
public void setDestination(SmbFile destination) {
this.destination = destination;
}
@Override
protected Void doInBackground(Integer... params) {
//check flag to excute exactly method
switch (params[0]) {
case 0:
//Call your download file method
downloadFile(file,desPath);
break;
case 1:
//Call your download folder method
downloadFolder(folder,tempStore);
//etc...
default:
break;
}
return null;
}
}
按下下载菜单时,您可以调用异步任务:
//Download the file
Helper helper = new Helper();
//set file and des path for download file
helper.setFile(your_file);
helper.setDesPath(your_despath);
//Excute the download file method
helper.excute(0);
//Download the folder
//set file and des path for download file
helper.setFolder(your_folder);
helper.setTempStore(your_tempStore);
//Excute the download folder method
helper.excute(1);
//etc...
注意:请仔细阅读此链接以了解如何使用 AsyncTask。