I wrote an android app a few years ago that does a fairly simple process. I set up a condition series consisting of different paces (walk, jog, sprint) with times associated with each segment: Walk 1 min, job 2 mins, sprint 3 mins. When I press the go button the app will display a countdown timer for each segment, a complete time timer and the pace (using GPS). There is a display, but the main feature is that the app uses sound to tell me long long till the next transition and what is coming up next.
For example, when it starts it produces a sound every second for 5 seconds then says "2 minutes". At the 30 sec mark a sound will occur. At 1 minute it will say "1 minute", another sound at 30 sec, then at 10 seconds before changing pace it will say "Next leg (jog) (or walk or sprint)" and play a sound the last 5 seconds. This way I do not need to look at the display to know where I am at in the condition program I created.
the problem: When I created this and ran it I was running two versions of Android behind the current one I now have (8.1.0) and now I run it on an LG Stylo 4. back then the device would go into sleep/standby mode, the screen going dark automatically or I hit the power button and the app would continue to operate just fine. Time would tick down, sounds would be made right on time.
This is the first time I installed and ran my app on the new phone/OS and let's say it did not go well. At one point I though I had 30 secs left and I didn't hear anything for over a minute. It seems like the app is now half getting paused, like 30 seconds turns into over 1 minute and there is no sound on the transitions.
Something has changed with Android it seems for this did not happen in past releases. What I want is for the program to keep running in real time when the device switches to sleep mode and while I read about excluding the app from Battery savings, that did not work.
In what way can I keep this app running in the background, counting down AND making sounds even when the phone is in sleep mode.
- OS version is 8.1.0
- Kernel 3.18.71
- build OPM1.171019.019
- Device: LM-Q710TS (LG Stylo 4)
The specific code in question is this:
//runs without a timer by reposting this handler at the end of the runnable
Handler timerHandler = new Handler();
Runnable timerRunnable = new Runnable() {
@Override
public void run() {
// do something here to display
processTime(); // process what to be done on a sec by sec basis
try {
timerHandler.postDelayed(this, 1000);
} catch (Exception ex){
}
}
};
I saw post that referred to using partial wakelock or maybe another version of timer, but can't find it now. Hoping there is a straight forward answer to this conundrum.