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 Answer
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.