¿Cómo puedo mantener un temporizador funcionando cuando se llama a onPause() en mi aplicación de Android?

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.

preguntado el 28 de agosto de 12 a las 11:08

Use a Service for that. That Service will be called from your Activity . -

1 Respuestas

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.

Respondido 28 ago 12, 11:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.