How to start timer that doesn't stop when activity closes
I would like to have an activity. In this activity I would like to have a button. When this button is pressed I would like a timer to start and be displayed "00:00:01". So far I have accomplished this using a Chronometer. What I would like to do now is to have this timer stay active (continue to count) even when the activity is not running.
So basically, i click a but开发者_运维问答ton and start the timer and it is counting and then I close the activity. I would then start the application again and in this activity I can see the counter counting and showing the elapsed time from when I clicked the button. For example, if I closed the activity and then came back 30 minutes later, the timer would show that time.
Can someone show me how to accomplish this or point me in the right direction?
Just save start systime in preferences and read it when activity restarts. There is no point to make timers, handlers etc. if you just have to write down start time and display
systime-starttime
every 250 ms (or choose your own period)
精彩评论