Android Chronometer start with defined value -


i have application in i'm displaying chronometer user he's doing. whenever activity goes background (wether home button, or back) save time (in seconds) , when activity brought back, want continue chronometer running same time. user might select different item list, , time different, , might turn off phone... can save time of chronometer, can't set start time.

from chornometer api, method setbase() states:

set time count-up timer in reference to.

on understanding, means if set value currenttime, it'll start counting 0. now, if want start value 17s thought setting base currenttime less time 17 seconds ago. like:

setbase(system.currenttimemillis() - (17 * 1000)). 

however doesn't work, , starts 0!

i read few other threads around here, , none of answers helped. starts 0!

thanks in advance.

i think you're going have keep track of time marks yourself.

chronometer mychrono; long basetime; long stoptime; long elapsedtime; 

when set base time, want use:

basetime = systemclock.elapsedrealtime() - stoptime; mychrono.setbase(basetime); 

when want see how time has passed, use:

elapsedtime = systemclock.elapsedrealtime() - mychrono.getbase(); 

take @ systemclock doc.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -