Make alert using onSensorChangeMethod

I’m trying to make a logic to alert me through Arduino and a light. Once the accelerometer sensor changed to a lower than 4g (g=gravity), I want to make a flashing light for three seconds or the light should flash three times. I made a for loop but doesn’t look like it works. Could you please tell me how to enhance this logic?
Thank you.

@Override
public final void onSensorChanged(SensorEvent event) {
    // The light sensor returns a single value.
    // Many sensors return 3 values, one for each axis.
    if (isListening) {
        double xx = event.values[0];
        double yy = event.values[1];
        double zz = event.values[2];
        TotalAccelerate = Math.round(Math.sqrt(Math.pow(xx, 2)
                + Math.pow(yy, 2)
                + Math.pow(zz, 2)));
        Log.i(DEBUG, "Accelerometer = " + TotalAccelerate);

        // here my code. 
        if (TotalAccelerate<=4){
                Handler handler = new Handler();
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        mConnectedThread.write("1");//send bit=1 through Buletooth to Arduino. 
                        Toast.makeText(getBaseContext(), "light 1", Toast.LENGTH_SHORT).show();
                    }
                },200);
                Handler handler4 = new Handler();
                handler4.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        mConnectedThread.write("0");
                        Toast.makeText(getBaseContext(), "light off", Toast.LENGTH_SHORT).show();
                    }
                },100);

        }
    }
}