I am trying to create an application that will allow me to receive data from several sensors at the same time. I still do not understand how I get there, so I started by introducing the SensorObject class for a structured layout.
This sensor object implements the SensorEventListener along with the usual onaccuracychanged and onsensorchanged methods. I left both methods empty since this class is inherited. I also applied the OnResume method as follows:
public void OnResume() {
sensorManager.registerListener(this, sensor,
SensorManager.SENSOR_DELAY_NORMAL);
}
Then I implemented an accelerometer object that extends the sensor object. Essentially, he does stuff on onSensor Changed.
My main questions are here 1) When in action, I never get the result from the accelerometer object, since it only introduces the onSensorChanged method until AFTER the code below has been executed :
AccelerometerObject ao = new AccelerometerObject(Sensor.TYPE_ACCELEROMETER, this);
ao.OnResume();
txtAccelerometerData = (TextView) findViewById(R.id.txtAccelerometerData);
txtAccelerometerData.setText(ao.toString());
Why does he not get access to the sensor data immediately, but goes sequentially? The object is still irrelevant because the onresume method was not available. Do I need to use separate threads? Efficiency is not so important, all I need is reliable data for experiments.
2) is it possible to implement several simultaneous sensors using the above approach?
Any help would be greatly appreciated.
The following is an AccelerometerObject on request.
public class AccelerometerObject extends SensorObject {
public float[] values;
public AccelerometerObject(int sensorType, Context _Context) {
super(sensorType, _Context);
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
@Override
public void onSensorChanged(SensorEvent event) {
AccelerometerValues = event.values;
onPause();
}
@Override
public String toString() {
if (values != null) {
return "X is " + values[0]
+ ", Y is " + values[1]
+ " and Z is "
+ values[2]);
} else
return "N/A";
}
}