java - CountdownTimer not getting Cancelled -


so looked @ many sources , whenever there such problem, it's because countdowntimer trying cancelled inside ontick. not issue. have countdowntimer in runnable. cancel timer, cancel runnable , still somehow gets called. here code below. appreciate help!

handler myhandler = new handler(); runnable runnable = new runnable() {     @override     public void run() {         countdowntimer countdowntimer = new countdowntimer(difference - (1000 * 60) + 2000, 60000) {             public void ontick(long millisuntilfinished) {          // work here             }             public void onfinish() {             // other work here         };         data.get(i).setcountdowntimer(countdowntimer);         data.get(i).getcountdowntimer().start();     } }; data.get(i).sethandler(myhandler); data.get(i).setrunnable(runnable); data.get(i).start(2000); 

the start function basically:

public void start(int milliseconds){     handler.postdelayed(runnable, milliseconds); } 

data list of objects each has own runnable, handler , countdowntimer.

here when cancel:

 data.get(i).getcountdowntimer().cancel();  data.get(i).terminate(); 

the terminate function basically:

public void terminate() {       handler.removecallbacks(runnable); } 

someone please tell me why countdowntimer somehow still runs after cancel way above; thanks!

update

in onfinish, have countdown on smaller interval. onfinish called when cancel countdowntimer? otherwise i'm out of ideas! thanks.

although made effort post relevant pieces of code, i'm having hard time imagining how fit together. example, when create runnable each data object, calls set , start countdown timer in run() method shown? i'm wondering how data , i accessible @ point. , if accessible, how know i have desired value when runnable comes out of queue , executes?

i agree cancel() should cause countdowntimer stop. note if start() called after cancel() timer start anew--it's not one-shot. if bug causing start() called second time, cancel didn't work.

all can suggest add bunch of log statements throughout code confirm assumptions when timers starting , being cancelled, , value of i each instance.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -