0

I am making a running app. A timer starts when i start a run. My activity starts from beginning when i unlock my phone screen. I know that i can save my objects state using onSaveInstanceState() but How can i keep the timer running when my phone screen is locked? Whats the best way to do that? Thanks in advance.

1
  • Use a Service for that. That Service will be called from your Activity .
    – Carnal
    Aug 28, 2012 at 10:52

1 Answer 1

2

Best solution depends on what are you planning to do. You can create a service with that timer, which will continue running even after onPause(). Or if you need it just to know how much time has elapsed, I would reccomend creating a timestamp at the start of run and comparing it ti current time whenever you need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.