java - How do I use a timer to run code again and again until a boolean value e.g. Testing is equal to true? -
this easy question but, how use timer run code again , again until boolean value e.g. testing equal true?
obviously use while loop don't want stop rest of work taking place on main ui thread
if process running simultaneously, use handler , use postdelayed(runnable, long) post callback implementing runnable interface.
a rather naive example:
final handler = new handler(); final runnable r = new runnable() { public void run() { if (<expression>) { // evaluated true, stuff , exit polling loop. } else { handler.postdelayed(this, <timeout>); } } handler.postdelayed(r, <timeout>);
Comments
Post a Comment