Note that there are some explanatory texts on larger screens.

plurals
  1. POObtaining sensor data for x seconds after onClick of a button
    primarykey
    data
    text
    <p>I'm still learning Android Development so sorry if this question seems stupid but I'm trying to obtain accelerometer data from the Phone for a limited time only. The goal is for the x-coordinate values from the sensor to be recorded only for about 3 seconds after a button is clicked.</p> <pre><code>public class AccelerometerTestingActivity extends Activity implements SensorEventListener { private SensorManager sensorManager; float x_event[]; @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.main); sensorManager=(SensorManager)getSystemService(SENSOR_SERVICE); // add listener. The listener will be HelloAndroid (this) class sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_GAME); } public void onAccuracyChanged(Sensor sensor,int accuracy){ } public void onSensorChanged(SensorEvent event){ // check sensor type if(event.sensor.getType()==Sensor.TYPE_ACCELEROMETER){ // assign directions float x=event.values[0]; x_event=addArrayElement(x_event,x); } } private float[] addArrayElement(float[] currentArray, float x) { // TODO Auto-generated method stub float newArray[] = new float[currentArray.length+1]; int i= 0; for(i=0;i&lt;currentArray.length;i++) { newArray[i] = currentArray[i]; } newArray[i+1]=x; return newArray; } </code></pre> <p>So x_event is an array filled with the X position of the Accelerometer periodically every SENSOR_DELAY_GAME.</p> <p>The thing is, this code records all values while activity is running.</p> <p>What I would like is for this array to be filled only from the time a button is clicked, and filled only for x seconds (haven't decided on the value of x yet). After that the array would be passed to another function for analysis.</p> <p>I just don't understand how to limit the Listener in time.</p> <p>Thank you for your help.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload