我編寫了一個應用程序來將傳感器數據保存到文件中。目標是以100 Hz保存IMU數據。 我使用Asynctask作爲存儲部分。一切似乎都很好;但是當我看到文件中的值時,會有很多次寫入很多數據。你有什麼想法:當使用Asynctask時,傳感器數據會被多次寫入
@Override
public final void onSensorChanged(SensorEvent event) {
//timestamp = (new Date()).getTime() + (event.timestamp - System.nanoTime())/1000000L;
timestamp = new Date().getTime();
// Handle accelerometer reading
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
bufferData[0] = event.values[0];
bufferData[1] = event.values[1];
bufferData[2] = event.values[2];
}
// Handle a gyro reading
else if (event.sensor.getType() == Sensor.TYPE_GYROSCOPE) {
bufferData[3] = event.values[0];
bufferData[4] = event.values[1];
bufferData[5] = event.values[2];
}
save_IMU save_imu = new save_IMU();
save_imu.execute();
}
請添加您的asynctask代碼。 –
class save_IMU extends AsyncTask protected void doInBackground(Void ... params)if(MainActivity.is_recording){ //創建文件夾名稱 store_data(); } return null; } protected void onPostExecute(布爾保存){ } }; –
trinamntn08
這裏mu代碼在Asynctask任務,對於錯誤的代碼抱歉,我不知道如何把它們清楚。 – trinamntn08