Stack Exchange
run method every x seconds in accelerometer
im trying to read onsensorchanged every x seconds,im using countdowntimer but not every seconds just one time when method is running,
private CountDownTimer delay;

@Override
public void onSensorChanged(SensorEvent event) {
    if (board!=null && event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
        float[] values = event.values;
        // Movement
        x =(int) Math.floor(values[0]);
        y =(int) Math.floor(values[1]);
        z =(int) Math.floor(values[2]);
        delay = new countleft(START_DELAY, INTERVAL);
        delay.start();
    }
}


class countleft extends CountDownTimer{
    public countleft(long millisInFuture, long countDownInterval) {
        super(millisInFuture, countDownInterval);
        // TODO Auto-generated constructor stub
    }
    @Override
    public void onFinish() {
        if(x>=3){
            board.right();
        }
        else if(x<=(-3)){
            board.left();
        }
        else if(y>=3){
            board.up();
        }
        else if(y<=(-3)){               
            board.down();
        }
        START_DELAY = 2000;
    }

need for advice

what you want to achieve?

To start with, onSensorChanged() is called continuously while input becomes available, possibly at a high rate. Every single call launches a new countdown timer, so you'll very quickly have thousands of countdown timers running in parallel. As blackbelt says, it would help if we knew exactly what you were trying to achieve.

im trying to run method board.up() and others to just every 1 seconds,

I'd suggest that in onSensorChanged(...) you alter
if (board!=null && event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)

to 
if (delay != null && board!=null && event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)

so that there's only one delay object at any point in time.  And then, in class countleft.onFinish(), instead of
START_DELAY = 2000;

you would need
delay = null;

so that the next countleft object can be created in onSensorChanged(...)

not work,,im set toast onTick() to see what is going on, but get stuck on 2000,1980 and 2000 again board method() not running

I suggest you use lots of Log.d(...) to work out what's going on.  Make sure to include the status of your variables like delay, board etc in the logging.
