android - Custom Count Up Timer -


i need count timer in application. browsed many forums subject, not find anything. understood can chronometer, have 2 problem chronometer:

  1. i cannot using chronometer in service because chronometer needs layout.
  2. i cannot initialize chronometer count more 1 hour.

my code:

stopwatch =  new chronometer (mainactivity.this); starttime = systemclock.elapsedrealtime(); stopwatch.start(); stopwatch.setonchronometerticklistener(new chronometer.onchronometerticklistener() {     @override     public void onchronometertick(chronometer arg0) {         countup = (systemclock.elapsedrealtime() - arg0.getbase()) / 1000;         string astext = (countup / 60) + ":" + (countup % 60);         log.i("t", astext);     } }); 

you can use countdowntimer in reverse , time elapsed.

long totalseconds = 30; long intervalseconds = 1;  countdowntimer timer = new countdowntimer(totalseconds * 1000, intervalseconds * 1000) {      public void ontick(long millisuntilfinished) {         log.d("seconds elapsed: " , (totalseconds * 1000 - millisuntilfinished) / 1000);     }      public void onfinish() {         log.d( "done!", "time's up!");     }  }; 

to start timer.

timer.start(); 

to stop timer.

timer.cancel(); 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -