Android `CountDownTimer` broken? -


i used 60 second timer count down using looked promising countdowntimer: http://developer.android.com/reference/android/os/countdowntimer.html

but i'm finding calls there hasn't been 60 calls ontick before onfinish executes. times find timer stuck on 1 instead of 0 because of reason. when stick in debugger, becomes more apparent. in fact, when put breakpoint in debugger, ontick has been called few 50 times before onfinish gets called.

am missing something, or should assume there no guarantee onfinish called if , if of supposed ontick functions have been called?

here's code:

    public someretrytimer(long future, long countdowninterval) {         super( 60*1000, 1000);         mcurrentcountdown = 60     }      @override     public void ontick(long l) {         mcurrentcountdown--;          dosomething();     }      @override     public void onfinish() {         finishstuff(); // @ point, find mcurrentcountdown not 0     } 

am doing wrong, or issue api? mean, looked @ source code , timer should synchronized in handler... messages getting posted out of order?

the ticks aren't @ guaranteed interval... that's why passes long ontick..

from docs

the calls ontick(long) synchronized object 1 call ontick(long) won't ever occur before previous callback complete. relevant when implementation of ontick(long) takes amount of time execute significant compared countdown interval.

so implies if work perform in ontick takes longer "regular interval" interval become more , more irregular. case when add overhead of debugger.

if must work in ontick, in thread not on timer's thread. don't think can or should rely on getting number of ticks. seems risky , error prone when realtime semantics not ensured os.


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -