我编写了一个应用程序来将传感器数据保存到文件中。目标是以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