Question

I'm working on a stopwatch style app that might be running for hours at a time. While debugging, I ran it overnight on my phone only to find that the app was released sometime during the night, and found in the morning it was not running like I'd hoped it would be.

In order to be more efficient, I keep track of what time the stopwatch was started and I only update the display while the app is visible. onPause() my timer thread (the one updating my UI) suspends and onResume() I resume the thread. This means while my app is backgrounded, nothing is happening and it gets flagged to be closed when left on for a long period of time.

In hopes of my app becoming more persistent, can I just put up an Ongoing Notification while the stopwatch is ticking?

Some may say that if my app isn't doing anything then it should close. As true as that appears to be, it's inherently keeping track of time. Even if that means it's not actively doing anything, it's waiting for the user to stop keeping track of time. I do not want the ongoing notification to simply keep my app alive, but also to remind the user that they're monitoring time with it.

If an Ongoing Notification won't keep my app persistent, what light-weight alternatives do I have?

Was it helpful?

Solution

Why do you need to keep the app running? Can't you just store running/paused/stopped state, and the start time, then recalculate the elapsed time when the app's started?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top