So I'm trying to analyze some data from the sensors. I want the array lists to "fill up" with the data, and then after 500ms, the thread to go away and process it. It seems like the thread only executes once (I know that's what is supposed to happen), but I can't figure out a way to execute it multiple times with it sleeping for 500ms. I tried using while(true)
, lock
, handler
, timer
and got nowhere.
public void onSensorChanged(SensorEvent sensorEvent) {
if (sensorEvent.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
accSensorVals = lowPass(sensorEvent.values.clone(), accSensorVals);
}
xAxisValues.add(accSensorVals[0]); // [0] - X axis
yAxisValues.add(accSensorVals[1]); // [1] - Y axis
zAxisValues.add(accSensorVals[2]); // [2] - Z axis
new Thread() {
public void run() {
try {
Thread.sleep(DELAY); // delay for 500 ms
checkSpikes(xAxisValues, yAxisValues, zAxisValues);
xAxisValues = new ArrayList<>();
yAxisValues = new ArrayList<>();
zAxisValues = new ArrayList<>();
} catch (Exception e) {}
}
}.start();
}