Android简单解析参数到AsyncTask

Android简单解析参数到AsyncTask,android,android-asynctask,Android,Android Asynctask,我只想将passinteger发送到AsyncTask。在doInBackground。例如: new LongOperation().execute ( 20 ); 我得到这个结果: 1266-2259/com.sample E/AsyncTask ------------------﹕ [Ljava.lang.Integer;@418e6bd0 我的代码: private class LongOperation extends AsyncTask<Integer, Void

我只想将passinteger发送到
AsyncTask
。在
doInBackground
。例如:

new LongOperation().execute ( 20 );
我得到这个结果:

1266-2259/com.sample E/AsyncTask ------------------﹕ [Ljava.lang.Integer;@418e6bd0
我的代码:

    private class LongOperation extends AsyncTask<Integer, Void, Integer> {

    @Override
    protected Integer doInBackground(Integer... params) {
        try {
            Log.e("AsyncTask ------------------ ", params+"");
            getFromServerAndUpdateDB ( params );
        } catch (JSONException e) {
            e.printStackTrace ();
        }
        return 0;
    }

    @Override
    protected void onPostExecute(Integer result) {
        updateDialog();
        notification ();
    }
    @Override
    protected void onPreExecute() {}

    @Override
    protected void onProgressUpdate(Void... values) {}
}
私有类LongOperation扩展了异步任务{
@凌驾
受保护的整数doInBackground(整数…参数){
试一试{
Log.e(“AsyncTask--------------------------”,params+”);
getFromServerAndUpdateDB(参数);
}捕获(JSONException e){
e、 printStackTrace();
}
返回0;
}
@凌驾
受保护的void onPostExecute(整数结果){
updateDialog();
通知();
}
@凌驾
受保护的void onPreExecute(){}
@凌驾
受保护的void onProgressUpdate(void…值){}
}

参数。。。是一个数组。尝试:

Log.e("AsyncTask ------------------ ", params[0] +"");

干杯

当您获得整数
参数时,您正在使用一种称为“varargs”的东西,如类型后面的三个点所示。这意味着params是一个字符串数组。要获取第一个数组,您需要像访问任何其他数组一样访问它:
params[0]


编辑:这是Oracle关于varargs的页面:

Params是一个整数数组,因此首先需要获取该数组的第一个索引

此外,将字符串传递到Log语句中,因此还需要将整数转换为字符串:

Log.e("AsyncTask ------------------ ", Integer.toString(params[0])+"");

这应该可以正常工作。

params[0]保留您的值。getFromServerAndUpdateDB在做什么,您实际遇到的问题在哪里。