I need to blink the LED every 2 seconds in my app. I have figured the code to switch the LED on and off using the following pieces of code:
Camera camera = Camera.open();
Parameters p = camera.getParameters();
p.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(p);
camera.startPreview();
p.setFlashMode(Parameters.FLASH_MODE_OFF);
camera.setParameters(p);
camera.startPreview();
Now as soon as the user presses the blink button, I need to execute the first piece of code for 2 seconds and then second piece of code for next 2 seconds. Also I need to stop the execution of this alternate LED on-off sequence as soon as the user presses the "Stop" button.
Any idea, how can I achieve this without making my app result in ANR?