android - countdowntimer skipping some milliseconds -


as can see last call ontick happening 2 seconds, next call 2 seconds later.

@override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate);  tv = new textview(this); this.setcontentview(tv); simpledateformat formatter = new simpledateformat("dd.mm.yyyy, hh:mm:ss:sss"); formatter.setlenient(false);   newtime = "31.12.2015, 23:59:59:999";  try {     newdate = formatter.parse(newtime);     milliseconds = newdate.gettime();       currenttime = system.nanotime();      diff = milliseconds - currenttime;   } catch (exception e) {     // todo auto-generated catch block     e.printstacktrace(); }  mycount counter = new mycount(milliseconds, 1000); counter.start();   } 

countdowntimer

public class mycount extends countdowntimer {     public mycount(long millisinfuture, long countdowninterval) {         super(millisinfuture, countdowninterval);     }      @override     public void onfinish() {     }      @override     public void ontick(long millisuntilfinished) {         serveruptimeseconds = (millisuntilfinished - system                 .currenttimemillis()) / 1000;         string serveruptimetext = string.format(                 "%d days %d hours %d minutes %d seconds",                 serveruptimeseconds / 86400,                 (serveruptimeseconds % 86400) / 3600,                 ((serveruptimeseconds % 86400) % 3600) / 60,                 ((serveruptimeseconds % 86400) % 3600) % 60);         tv.settext(serveruptimetext);     } } 

output:

10 seconds  8 seconds  6 seconds  4 seconds  

p.s ~ check video more info

https://www.dropbox.com/s/7b3hme5ekdqpfi1/79789789.avi?dl=0

try out :

timertask runtimertask = new timertask() {     @override     public void run() {         // code     }); };  timer timer = new timer(); timer.scheduleatfixedrate(runtimertask, 0, 500); 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -