这是我的问题的后续跟进:Android线程可运行的性能
我在应用程序的同步方法上遇到了一些困难
我正在轮询传感器并在传感器值发生变化时将其存储到数组中
float[] accelerometerMatrix = new float[3];
float[] accelerometerWorldMatrix = new float[3];
float[] gyroscopeMatrix = new float[3];
float[] gravityMatrix = new float[3];
float[] magneticMatrix = new float[3];
float[] rotationMatrix = new float[9];
class InsertHandler implements Runnable {
public void run() {
//get values from arrays and insert into db
}
}
public void onSensorChanged(SensorEvent event) {
sensor = event.sensor;
int i = sensor.getType();
if (i == MainActivity.TYPE_ACCELEROMETER) {
accelerometerMatrix = event.values;
} else if (i == MainActivity.TYPE_GYROSCOPE) { …Run Code Online (Sandbox Code Playgroud)