android - How to update values while method is running - Java -


so have weird problem cannot understand why doesn't work. building strobe light part of app , have created separate strobelight class. when call turnon method or update method, intervals never changed. guess make easier explain using code:

public class strobelight{  private int delayon, delayoff;  public void turnstrobeon(){...}  public void update(int a_delayon, int a_delayoff){     delayon = a_delayon;     delayoff = a_delayoff; }  public void turnon(int a_delayon, int a_delayoff){     delayon = a_delayon;     delayoff = a_delayoff;     this.turnstrobeon(); } 

depending on whether strobe light on or not, 1 of these methods called change turn on strobe light specified intervals or change intervals.

instead of changing intervals custom, application uses smallest possible intervals when calling thread.sleep() flashlight being on or off

edit: thread code, , code turns flashlight on

public void turnstrobeon(){

    ( int = 0; < 3; i++){          isincycle = true;          cam = camera.open();         parameters p = cam.getparameters();         p.setflashmode(parameters.flash_mode_torch);         cam.setparameters(p);         cam.startpreview(); // flashlight on         lightison = true;         new thread(new runnable() {             public void run() {                 try {                     thread.sleep(delayon);                 } catch (interruptedexception e) {                     e.printstacktrace();                 }             }         }).start();          cam.stoppreview();         cam.release();         lightison = false;         new thread(new runnable() {             public void run() {                 try {                     thread.sleep(delayoff);                 } catch (interruptedexception e) {                     e.printstacktrace();                 }             }         }).start();      } //end of loop          isincycle = false;    } // end of turnstrobeon 

you might want else's advice on buy best guess can't specific on sleep(). don't forget use miliseconds that. i'd suggest using android handler , doing postdelayed instead of sleeping.

how pause / sleep thread or process in android?


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -