I have an application with a Chronometer in its main activity. The Chronometer is used as a timer. This timer should keep running once the device’s screen is off. I noticed that once the timer is running and I turn off my screen for a longer period of time, and turn in on again, the Chronometer stops running (it’s reset to 00:00). If I off my screen for perhaps 2 hours, it would still run, but once it’s over night (approx. 8 hours), the next morning the Chronometer stopped running. How can I achieve a behavour that the Chronometer runs until the user turns it off, even if the screen is off for some hours? Thanks.
I have an application with a Chronometer in its main activity. The Chronometer is
Share
Is it really important to keep it running? It will drain user’s battery.
I mean, why don’t just save the time when the app is closed or pause or whatever (as simple as saving a long:
System.currentTimeMillis())… then, when it’s restarted or resumed just calculate how much it should have run by the time you resumed it.