我想要的是将一个int变量传递给我的AsyncTask.
int position = 5;
我宣布我的AsyncTask是这样的:
class proveAsync extends AsyncTask<int, Integer, Void> {
protected void onPreExecute(){
}
protected Void doInBackground(int... position) {
}
.
.
.
但我得到一个错误,它是以下内容:
Type argument cannot be of primitive type
我只能传递一个int []和Integer变量,但从不传递一个int变量,我执行我的AsyncTask,如下所示:
new proveAsync().execute(position);
我能做些什么才能通过这个职位吗?
提前致谢!
将参数传递为Integer
class proveAsync extends AsyncTask<Integer, Integer, Void> {
protected void onPreExecute(){
}
protected Void doInBackground(Integer... position) {
int post = position[0].intValue();
}
.
.
.
执行时执行此操作
new proveAsync().execute(new Integer(position));
您可以使用intValue()获取AsyncTask中的int值
翻译自:https://stackoverflow.com/questions/32069309/how-can-i-pass-a-primitive-int-to-my-asynctask