I am trying to build an application that would allow me to retrieve data from multiple sensors simultaneously. I still have not figured out how I will get there, so I started by implementing a SensorObject class for a structured layout.
This sensorobject implements the SensorEventListener together with the usual onaccuracychanged and onsensorchanged methods.I have left both methods empty for now since this class is inherited.
I also implemented OnResume method like so:
public void OnResume() {
sensorManager.registerListener(this, sensor,
SensorManager.SENSOR_DELAY_NORMAL);
}
Successively I implemented an accelerometer object that extends the sensor object. Substantially, it does stuff in the onSensor Changed.
My main questions lie here
1) When in the activity, I am never getting a result from the accelerometer object, since it only enters the 'onSensorChanged' method until AFTER the below code has been executed:
AccelerometerObject ao = new AccelerometerObject(Sensor.TYPE_ACCELEROMETER, this);
ao.OnResume();
txtAccelerometerData = (TextView) findViewById(R.id.txtAccelerometerData);
txtAccelerometerData.setText(ao.toString());
Why isn't it accessing the sensor data immediately but proceeding sequentially? The object still has no values since the onresume method hasnt been accessed. Will i need to use seperate threads? Efficiency is not that important, all I need is valid data for experimentation.
2) is it possible to implement multiple simultaneous sensors using the above approach?
Any help would be greatly appreciated.
Below is the AccelerometerObject as requested.
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";
}
}