0

I trying to turn ON the phone flash light every second. I have been searching but nothing found useful.

This is the code that I am using:

Thread t = new Thread() {

@Override
public void run() {
seconds = 0;
  try {
    while (seconds<11) {
      Thread.sleep(1000);
      runOnUiThread(new Runnable() {
        @Override
        public void run() {

        // Put code here!

        seconds++;
        }
      });
    }
  } catch (InterruptedException e) {
 }
}
};

t.start();

I will really appreciate your help! Thanks.

Roberto Zuniga
  • 437
  • 1
  • 7
  • 16

1 Answers1

0

Creating the loop is bad idea. Try to use handler http://developer.android.com/reference/android/os/Handler.html

handler.postDelayed(Runnable r, long delayMillis)

use this at the and of runnable code.

Vyacheslav
  • 26,359
  • 19
  • 112
  • 194