counter - How do I use Android's CountDownTimer? -
how use android's countdowntimer?
i want have following scenario:
boolean 3_s_passed = false; // setup counter change 3_s_passed=true when finishes counter.start(); while(true){ if(3_s_passed || user_is_done) break; // stuff may set user_is_done true }
so either 3 seconds passed or user finishes , i'm out of loop. while-loop code run before counter finishes? understanding of countdowntimer correct?
thanks help
you use handler this. make runnable
task complete after 3 seconds or when user task. post 3 seconds , remove callbacks if user whatever. code same below shows how use handler
isn't looping allow user make action you'll have figure out on own :)
runnable action = new runnable(){ public void run(){ //... } }; mhandler.postdelayed(action, 3000); if(userdone){ mhandler.removecallbacks(action); mhandler.post(action); }
Comments
Post a Comment