我想在后台任务执行之前在异步任务中操作特定 View ,但不确定如何将所需参数传递给该方法。当我做这样的事情时,我只是得到一个空指针
class CalcFib extends AsyncTask<Integer, Void, Long> {
private View v;
private int index;
public CalcFib(int i){
this.index = i;
}
@Override
protected void onPreExecute() {
//do something with this.index
}
@Override
protected Long doInBackground(Integer... params) {
long t = 1234;
return t;
}
@Override
protected void onPostExecute(Long result) {
}
}
最佳答案
向CalcFib
添加构造函数,并通过构造函数将所需的值传递给实例。
关于android - 我可以在异步任务中将参数传递给 preExecute() 方法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18818466/