Code example for AtomicInteger

Methods: compareAndSet

0
 
 
    private void readAccelerometerValue() 
    { 
        debugTrace(".readAccelerometerValue()"); 
        if (gotSensorData.compareAndSet(IDLE, WAITING))
        { 
            sensorManager.registerListener(this,
                                           sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
                                           SensorManager.SENSOR_DELAY_NORMAL);
        } 
    } 
 
    @Override 
    public void onAccuracyChanged(Sensor arg0, int arg1) {}
 
    private String storedAccelerationString(float[] a)
    { 
        return String.format("%2.3f %2.3f %2.3f", a[0], a[1], a[2]);
    }