September 8th, 2011, 11:02 AM
|
#1 (permalink)
|
|
Junior Member
Join Date: Mar 2011
Location: Mexico
Posts: 30
Device(s): Samsung Galaxy 5 (GT-I5500L), Samsung Galaxy Ace
Thanks: 11
Thanked 2 Times in 2 Posts
|
How can I get the values from the "public void onSensorChanged(SensorEvent event) " to another?
Hi!! I'm making an application on Android and I'm using the accelerometer sensor of my phone.
Part of the code is:
Code:
public class OtroacelbtActivity extends Activity implements SensorEventListener {
private float x = 0, y = 0, z = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
protected void onResume() {
super.onResume();
SensorManager sm = (SensorManager) getSystemService(SENSOR_SERVICE);
List<Sensor> sensors = sm.getSensorList(Sensor.TYPE_ACCELEROMETER);
if (sensors.size() > 0) {
sm.registerListener(this, sensors.get(0), SensorManager.SENSOR_DELAY_UI );
}
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {}
@Override
public void onSensorChanged(SensorEvent event) {
synchronized (this) {
String message=null;
x = event.values[0];
y = event.values[1];
z = event.values[2];
}
}
}
I want to use the x,y and z values on another method, but even they are global variables, if I call them just like that on the other method, thee only give the "null" value (cause it's a void method).
How can I do it???
Thanks.
|
|
|