Problem is that Sensors send you raw analog data. So they are continuous and data is raw. Or if you are using other sensors too, this method might be called by other sensors. So check type of sensor also.
public void onSensorChanged(SensorEvent event) {
lightLux = event.values[0]; // Final output of this sensor.
Lux = String.valueOf(lightLux);
if(event.sensor.getType()==Sensor.TYPE_LIGHT){
final float currentReading = event.values[0];
if (currentReading > 0){
//ON
}
else
{//OFF
}
}
}
Also you will see change in value everytime, because it sends too detailed value as it is raw data. You can cast it to int
if you don't want this.
int value= (int) event.values[0];
Hope it helps! Good luck